Created
May 22, 2017 00:26
-
-
Save DavidBuchanan314/7e070ec56d53df6ddec7fe3ee596842d 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
""" | |
Solution for RCTF 2017 challenge "Need a waiter" | |
714 points, 9 solves | |
""" | |
import codecs | |
rearranger = [11,15,14,13,7,9,6,3,0,1,2,10,5,12,8,4] | |
ciphertext = "fc55e53d4bee0c96a781e1cffe7f3dce433242df298f2a97edc235eb191c9da6d22116cdba99beb14ca6d4bd77098e0797" | |
ciphertext = [x for x in bytes.fromhex(ciphertext)] | |
def rng(seed): | |
return (123 * seed + 59) % 65536 | |
seed = ciphertext.pop() ^ 66 | |
randomised = [] | |
for i in range(len(ciphertext)): | |
seed = rng(seed) | |
ciphertext[i] ^= seed % 256 | |
reordered = [] | |
for startpoint in range(0,len(ciphertext),len(rearranger)): | |
chunk = ciphertext[startpoint:startpoint+len(rearranger)] | |
for i in range(len(rearranger)): | |
reordered.append(chunk[rearranger.index(i)]) | |
rot13 = "".join(chr(x) for x in reordered if x != 0) | |
print(codecs.encode(rot13, 'rot_13')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment