Created
December 14, 2016 08:57
-
-
Save bongtrop/5af6a39b0663844fc43f1e3fc18dc936 to your computer and use it in GitHub Desktop.
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
import itertools | |
from hashlib import md5 | |
vig = "ABCDEFGHIJKLMNOPQRSTUVWXYZ{}" | |
plaintext = "SECCON{???????????????????????????????????}" | |
md5text = "f528a6ab914c1ecf856a1d93103948fe" | |
cipher = "LMIG}RPEDOEEWKJIQIWKJWMNDTSR}TFVUFWYOCBAJBQ" | |
k = ["?"]*12 | |
def vir(x, y): | |
k = vig.find(x) - vig.find(y) | |
return vig[k if k>=0 else len(vig) + k] | |
for i, p in enumerate(plaintext): | |
if p != '?': | |
k[i%len(k)] = vir(cipher[i], p) | |
k[7] = 'E' | |
key = "".join(k).replace('?', '') | |
for k in itertools.product(vig, repeat=12-len(key)): | |
kk = key + "".join(k) | |
tp = [ vir(c, kk[i%len(kk)]) for i, c in enumerate(cipher) ] | |
if md5("".join(tp)).hexdigest() == md5text: | |
print "".join(tp) | |
exit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment