Skip to content

Instantly share code, notes, and snippets.

@volpino volpino/reader.py
Created Dec 26, 2014

Embed
What would you like to do?
Reader (PPC9) - Advent calendar CTF 2014
from socket import socket
code0 = {}
code0["0"] = "100010100"
code0["1"] = "101001000"
code0["2"] = "101000100"
code0["3"] = "101000010"
code0["4"] = "100101000"
code0["5"] = "100100100"
code0["6"] = "100100010"
code0["7"] = "101010000"
code0["8"] = "100010010"
code0["9"] = "100001010"
code0["A"] = "110101000"
code0["B"] = "110100100"
code0["C"] = "110100010"
code0["D"] = "110010100"
code0["E"] = "110010010"
code0["F"] = "110001010"
code0["G"] = "101101000"
code0["H"] = "101100100"
code0["I"] = "101100010"
code0["J"] = "100110100"
code0["K"] = "100011010"
code0["L"] = "101011000"
code0["M"] = "101001100"
code0["N"] = "101000110"
code0["O"] = "100101100"
code0["P"] = "100010110"
code0["Q"] = "110110100"
code0["R"] = "110110010"
code0["S"] = "110101100"
code0["T"] = "110100110"
code0["U"] = "110010110"
code0["V"] = "110011010"
code0["W"] = "101101100"
code0["X"] = "101100110"
code0["Y"] = "100110110"
code0["Z"] = "100111010"
code0["-"] = "100101110"
code0["."] = "111010100"
code0[" "] = "111010010"
code0['"'] = "111001010"
code0["/"] = "101101110"
code0["+"] = "101101110"
code0["%"] = "110101110"
code0["SHIFT1"] = "100100110"
code0["SHIFT2"] = "111011010"
code0["SHIFT3"] = "111010110"
code0["SHIFT4"] = "100110010"
code0["START"] = "101011110"
code0["STOP"] = "1010111101"
code0["UNKNOWN"] = "101110110"
mapping = {v: k for k, v in code0.iteritems()}
s = socket()
s.connect(("adctf2014.katsudon.org", 43010))
while True:
msg = s.recv(2048)
msg += s.recv(2048).strip()
i = 0
binary = ""
print msg
while i < len(msg):
#print i, repr(msg[i]), binary
if msg[i] == " ": # 00
binary += "00"
i += 2
else:
if msg[i+2] == "\x88": # 11
binary += "11"
elif msg[i+2] == "\x90": # 01
binary += "01"
elif msg[i+2] == "\x8c": # 10
binary += "10"
else:
print 'UNKNOWN ' + repr(msg[i+2])
raise Exception
i += 3
print binary
res = ""
for i in range(0, len(binary), 9):
if len(binary[i:i+9]) == 9 and len(mapping[binary[i:i+9]]) == 1:
res += mapping[binary[i:i+9]]
res = res[:10]
print res
s.sendall(res + "\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.