Created
October 13, 2015 16:21
-
-
Save stewartpark/920b7a58c941441acb8c to your computer and use it in GitHub Desktop.
Foobar password decryption
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 python3 | |
from functools import lru_cache | |
""" | |
The encryption equation is given as: | |
D_i = (129M_i) XOR (M_(i-1)) (mod 256) | |
where D denotes a encrypted string, M is the message. | |
Thus, the message equation derived from the original equation should be: | |
M_i = 256c_i * (D_i XOR (M_(i-1))) / 129 | |
where c_i is an integer that makes M_i closed under the integer field | |
""" | |
digest = lambda i: [0, 129, 3, 129, 7, 129, 3, 129, 15, 129, 3, 129, 7, 129, 3, 129][i] | |
selInt = lru_cache()(lambda x, y: \ | |
int(x) if int(x) == x else y()) | |
message = lru_cache()(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