Skip to content

Instantly share code, notes, and snippets.

@jvarho
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jvarho/09baddea8e2cd81f7609 to your computer and use it in GitHub Desktop.
Save jvarho/09baddea8e2cd81f7609 to your computer and use it in GitHub Desktop.
collision test for iterated, truncated sha1
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)
@jvarho
Copy link
Author

jvarho commented Jun 18, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment