Created
April 13, 2021 00:09
-
-
Save dhrumilp15/1a38e48e4db169f79c21603708c6b799 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
def recurse(plaintexts, ciphertexts, kcands, keyers=[], depth=1): | |
if depth > 5: | |
return None, None | |
for k in kcands: | |
dciphertexts = ciphertexts[:] | |
# DECRPYT CIPHERTEXTS WITH THE CURRENT KEY | |
for pair in range(len(dciphertexts)): | |
ci1, ci2 = map(int, dciphertexts[pair], repeat(16)) | |
# undo modular multiplication by odd-ed key, reversal, | |
# xor by guessed key | |
ci1 = g((ci1 * pow(k | 1, -1, 1 << 64)) % (1 << 64)) ^ k | |
ci2 = g((ci2 * pow(k | 1, -1, 1 << 64)) % (1 << 64)) ^ k | |
dciphertexts[pair] = [hex(ci1)[2:], hex(ci2)[2:]] | |
# If the decrypted ciphertexts are the same as the plaintext, we're done! | |
if all([int(dciphertexts[i][j], 16) == int(plaintexts[i][j], 2) | |
for j in range(0, 2) for i in range(len(dciphertexts))]) == True: | |
return dciphertexts, [k] + keyers | |
# SOLVE FOR THE NEXT ODD-ED KEY | |
dkcands = crack_subkey(dciphertexts) | |
if dkcands is None: | |
continue | |
v = recurse(plaintexts, dciphertexts, | |
dkcands, [k] + keyers, depth + 1) | |
if v is not None: | |
return v |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment