Skip to content

Instantly share code, notes, and snippets.

@jimtla
Created April 1, 2013 21:32
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 jimtla/5287938 to your computer and use it in GitHub Desktop.
Save jimtla/5287938 to your computer and use it in GitHub Desktop.
import skein
from random import choice
target = '5b4da95f5fa08280fc9879df44f418c8f9f12ba424b7757de02bbdfbae0d4c4fdf9317c80cc5fe04c6429073466cf29706b8c25999ddd2f6540d4475cc977b87f4757be023f19b8f4035d7722886b78869826de916a79cf9c94cc79cd4347d24b567aa3e2390a573a373a48a5e676640c79cc70197e1c5e7f902fb53ca1858b6'
def bitcount(v):
if v > 0:
return (v & 1) + bitcount(v>>1)
else:
return 0
def check_hash(hash):
hashed = skein.skein1024(hash.encode('ascii')).hexdigest()
difference = 0
for idx, char in enumerate(target):
difference += bitcount(int(char, 16) ^ int(hashed[idx], 16))
return difference
chars = 'abcdefghijklmnopqrstuvwxyz0123456789'
def random_string(length):
c = ''
for i in range(length):
c += choice(chars)
return c
best = 1025
for i in range(10, 100):
for j in range(100000):
s = random_string(i)
r = check_hash(s)
if r < best:
best = r
print(s, r)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment