CSCAMP CTF 2012 - Crypto 400
This is the solution script:
import re, requests, string
def main():
print "Solver for CScamp Crypto 400"
print "by amonn"
print "Decomposing raw crypto data..."
parsed = parse_raw()
print "Parsed data: %s." % "".join(i + ", " for i in parsed)[:-2]
print "Working on grabbing keys using lowercase alpha set..."
keyset = build_key()
print "Keys retrieved."
print "Decrypting parsed data with keyset..."
print "Decrypted key is %s." % decrypt(parsed, keyset).upper() # the key is
required in uppercase
def decrypt(parsed, key_dict):
decrypt = ""
for i in parsed:
decrypt += key_dict[i]
return decrypt
def build_key():
def request_key(letter):
url = "http://176.9.193.13/CrYpt0ch4l12554222426.php"
payload = {'key': letter}
r = requests.get(url, params=payload)
p = re.compile("([01]{2})
([01]{2})
([01]{2})
")
s = p.search(r.text)
if s:
key = "".join(i for i in s.groups()).encode("ascii", "ignore")
print "%s: %s" % (letter, key)
return key
else:
return None
key_dict = {}
for i in string.ascii_lowercase:
key_dict[request_key(i)] = i
return key_dict
def parse_raw():
raw_search=["011001011001111010101010011111111110111101101110111010",
"110010110010000010101010100101010011011011011100000101",
"001110100010100010100010001000110010111010100000100011"
]
# Assuming that there is no sequential rule for each character, we simply
# extract the bits of a specific encoded letter through this scheme:
# 01
# 23
# 45
the_list = []
for i in raw_search:
em = [h+k for h,k in zip(i[0::2], i[1::2])]
for j in range(len(em)):
if len(the_list) < j + 1: the_list.append("")
the_list[j] += em[j]
return the_list
if __name__ == "__main__":
main()
Leave a Comment