Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

@jvarho jvarho commented Jun 18, 2014

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