Skip to content

Instantly share code, notes, and snippets.

@stewartpark
Created October 11, 2015 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 stewartpark/d03073c6c4b8cb42d171 to your computer and use it in GitHub Desktop.
Save stewartpark/d03073c6c4b8cb42d171 to your computer and use it in GitHub Desktop.
Foo.bar hash it out
#!/usr/bin/env python
def memoize(f):
memo = {}
def helper(*args):
x = str(args)
if x not in memo:
memo[x] = f(*args)
return memo[x]
return helper
digest = lambda i: [0, 129, 3, 129, 7, 129, 3, 129, 15, 129, 3, 129, 7, 129, 3, 129][i]
selInt = memoize(lambda x, y: \
int(x) if int(x) == x else y())
message = memoize(lambda i, c: \
selInt(
(256.0*c + (digest(i) ^ message(i-1, 0))) / 129.0,
lambda: message(i, c+1)
) if i >= 0 else 0)
print [digest(x) for x in range(16)]
print [message(x, 0) for x in range(16)]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment