import%20marimo%0A%0A__generated_with%20%3D%20%220.15.3%22%0Aapp%20%3D%20marimo.App()%0A%0Awith%20app.setup%3A%0A%20%20%20%20import%20marimo%20as%20mo%0A%20%20%20%20import%20matplotlib.pyplot%20as%20plt%0A%20%20%20%20import%20numpy%20as%20np%0A%20%20%20%20import%20pandas%20as%20pd%0A%0A%20%20%20%20plt.style.use(%22seaborn-v0_8-whitegrid%22)%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20%23%20be%20careful%20here%2C%20the%20last%20element%20is%20never%20included%0A%20%20%20%20np.arange(0%2C%205)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20%23%20first%20notice%20how%20this%20leads%20to%20an%20overflow%20(without%20any%20warning)%0A%20%20%20%20np.power(2%2C%20np.arange(0%2C%2065))%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20_grains%20%3D%20np.sum(np.power(2.0%2C%20np.arange(0%2C%20256)))%0A%20%20%20%20print(_grains)%0A%20%20%20%20n%20%3D%2020000%20*%2025%20*%201000%20*%2050000.0%0A%20%20%20%20print(n)%0A%20%20%20%20print(_grains%20%2F%20n)%0A%20%20%20%20print(np.log2(50000%20*%201000%20*%2025))%0A%20%20%20%20np.power(2.0%2C%2034)%20%2F%2020000%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_()%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20%20%20%20%20I%20guess%20it's%20fair%20to%20say%20that%20powers%20of%20%242%24%20grow%20very%20fast.%20This%20is%20exponential%20growth%20in%20practice...%0A%20%20%20%20%20%20%20%20We%20would%20need%20approximately%20%24750000%24%20superships%2C%20each%20packed%20with%20%2420000%24%20containers%2C%0A%20%20%20%20%20%20%20%20each%20container%20packed%20with%20%2425%24%20tons%20of%20rice.%0A%0A%20%20%20%20%20%20%20%20Annual%20production%20of%20rice%20in%20tons%20is%20%24700%20000%20000%24%0A%20%20%20%20%20%20%20%20We%20would%20produce%20for%20the%20next%20500%20years%20at%20the%20current%20rate...%0A%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20(np.power(2.0%2C%2064)%20-%201)%20%2F%20(50000%20*%201000%20*%20700000000)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20_grains%20%3D%20np.power(2%2C%204)%20-%201%0A%20%20%20%20print(_grains)%0A%20%20%20%20print(hex(_grains))%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20integer%20%3D%20int(%22affe%22%2C%2016)%0A%20%20%20%20return%20(integer%2C)%0A%0A%0A%40app.cell%0Adef%20_(integer)%3A%0A%20%20%20%20bin(integer)%0A%20%20%20%20hex(integer)%0A%20%20%20%20integer%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20frame%20%3D%20pd.DataFrame(index%3Dnp.arange(0%2C%2016))%0A%20%20%20%20frame%5B%22binary%22%5D%20%3D%20pd.Series(%7Ba%3A%20format(a%2C%20%220%3E4b%22)%20for%20a%20in%20frame.index%7D)%0A%20%20%20%20frame%5B%22hexadecimal%22%5D%20%3D%20pd.Series(%7Ba%3A%20format(a%2C%20%220%3E1x%22)%20for%20a%20in%20frame.index%7D)%0A%20%20%20%20return%20(frame%2C)%0A%0A%0A%40app.cell%0Adef%20_(frame)%3A%0A%20%20%20%20frame%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20%23%20It's%20trivial%20to%20convert%20any%20hashcode%20into%20a%20binary%20or%20decimal%20form...%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20%23%20age%20of%20the%20universe%20in%20seconds%0A%20%20%20%20%23%20number%20of%20atoms%20in%20the%20universe%0A%20%20%20%20%23%20operations%20the%20world-fastest%20supercomputer%20can%20perform%20per%20second%20200%20petaflops%20%3D%20200%20*%2010%5E15%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20%23%20Every%20integer%20can%20be%20represented%20as%20binary%2C%20hexadecimal%20or%20decimal%20number.%20A%20hashcode%20is%20a%20hexadecimal%20number...%0A%20%20%20%20%23%20In%20fact%2C%20it's%20fair%20to%20say%20that%20typcially%20a%20hashcode%20is%20a%20large%20hexadecimal%20number.%0A%20%20%20%20%23%20Nevertheless%2C%20the%20range%20of%20possible%20hashcodes%20is%20finite!%0A%20%20%20%20%23%20So%20collisions%20do%20exist.%0A%20%20%20%20%23%20It's%20just%20very%20hard%20to%20find%20them.%20If%20you%20find%20them%2C%20we%20should%20write%20a%20paper%20together...%0A%20%20%20%20%23%20It's%20trivial%20to%20compute%20the%20hashcode%20of%20any%20given%20string...%0A%20%20%20%20%23%20It's%20kind%20of%20impossible%20to%20do%20the%20inverse%20(which%20does%20not%20exist%20as%20mapping%20is%20not%20injective)%0A%20%20%20%20%23%20but%20find%20one%20string%20that%20results%20in%20that%20hashcode%0A%20%20%20%20%23%20You%20would%20have%20to%20apply%20brute%20force%0A%20%20%20%20%23%20We%20are%20very%20interested%20in%20the%20problem%20of%20finding%20a%20hashcode%20below%20a%20given%20threshold%2C%0A%20%20%20%20%23%20that%20problem%20is%20already%20hard%20enough...%0A%20%20%20%20%23%20All%20collisions%20for%20simpler%20hash%20functions%20have%20been%20found%20using%20a%20birthday%20attack...%0A%20%20%20%20return%0A%0A%0Aif%20__name__%20%3D%3D%20%22__main__%22%3A%0A%20%20%20%20app.run()%0A
2c5ee7c0f3a0fc5522340ab3d872f6f20810671f7e326c0f717820544e5efd63