Skip to content

Instantly share code, notes, and snippets.

@awave1
Created January 30, 2019 20:37
Show Gist options
  • Save awave1/3ec77f12c2473c3d102812b72a876f52 to your computer and use it in GitHub Desktop.
Save awave1/3ec77f12c2473c3d102812b72a876f52 to your computer and use it in GitHub Desktop.
from math import log2
from itertools import product
def h(p):
a, b, c, d = p
calc = ((a ** 4) + (b ** 3) + (c ** 2) + d)
return calc % 100
def find_collisions():
collisions = {}
passwords = product(range(10), repeat=4)
og_pass = (7, 8, 1, 9)
hash_to_check = h(og_pass)
for p in passwords:
calculated_hash = h(p)
if og_pass != p and calculated_hash == hash_to_check:
collisions[p] = calculated_hash
for p in collisions:
print(p)
print(f'total collisions: {len(collisions.keys())}')
if __name__ == '__main__':
find_collisions()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment