Skip to content

Instantly share code, notes, and snippets.

@olafurw
Created March 14, 2015 21:28
Show Gist options
  • Save olafurw/c2d33fb5336f15fa0745 to your computer and use it in GitHub Desktop.
Save olafurw/c2d33fb5336f15fa0745 to your computer and use it in GitHub Desktop.
Repetitive hashing collision
import hashlib
iteration_length = 10
hash_length = 5
set_length = pow(16, hash_length)
fs = set()
for i in range(0, set_length):
x = format(i, 'x').zfill(hash_length)
fs.add(x)
print len(fs)
for i in range(0, iteration_length):
nfs = set()
for i in fs:
h = hashlib.md5()
h.update(i)
nfs.add(h.hexdigest()[:hash_length])
print len(nfs)
fs = nfs
#############################
Hash length: 1
16
8
5
5
5
5
Hash length: 2
256
161
116
93
78
67
Hash length: 3
4096
2608
1940
1559
1316
1142
Hash length: 4
65536
41486
30774
24579
20537
17705
Hash length: 5
1048576
662422
490920
391934
327017
280856
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment