Created
October 11, 2015 21:32
-
-
Save stewartpark/d03073c6c4b8cb42d171 to your computer and use it in GitHub Desktop.
Foo.bar hash it out
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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