Skip to content

Instantly share code, notes, and snippets.

Created October 9, 2013 04:40
Show Gist options
  • Save anonymous/6896302 to your computer and use it in GitHub Desktop.
Save anonymous/6896302 to your computer and use it in GitHub Desktop.
import hashlib
import timeit
from random import randint
def hashx(x):
m = hashlib.sha1()
m.update(x)
return m.digest()
def random_phone_number():
return ''.join(str(randint(0, 9)) for _ in xrange(10))
def crack(n):
for _ in range(n):
num = random_phone_number()
hashx(num)
if __name__ == '__main__':
n = 100000
t = timeit.timeit(
'crack(' + str(n) + ')',
setup='from __main__ import crack',
number=1)
print '%f ms / number' % (t * 1000. / n)
print '%f hrs for all numbers' % ((t / n) * (10**10) / 3600.0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment