Last active
August 29, 2015 14:02
-
-
Save jvarho/09baddea8e2cd81f7609 to your computer and use it in GitHub Desktop.
collision test for iterated, truncated sha1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import hashlib | |
def H(s): | |
for i in xrange(N): | |
s = hashlib.sha1(s).hexdigest()[:4] | |
return s | |
n = 1000000 | |
for N in range(1, 17): | |
collisions = 0 | |
for i in xrange(n): | |
collisions += H('a%dN%d' % (i, N)) == H('b%dN%d' % (i, N)) | |
print N, int(n * 1. / collisions) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Used for this Crypto Stackexchange answer. Plot here.