Created
April 19, 2016 02:29
-
-
Save zTrix/fd55892001c011a5d777a262eda0c0c1 to your computer and use it in GitHub Desktop.
morset writeup
This file contains hidden or 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
#!/usr/bin/env python2 | |
#-*- coding:utf-8 -*- | |
import os, sys | |
from zio import * | |
import hashlib | |
CODE = {'A': '.-', 'B': '-...', 'C': '-.-.', | |
'D': '-..', 'E': '.', 'F': '..-.', | |
'G': '--.', 'H': '....', 'I': '..', | |
'J': '.---', 'K': '-.-', 'L': '.-..', | |
'M': '--', 'N': '-.', 'O': '---', | |
'P': '.--.', 'Q': '--.-', 'R': '.-.', | |
'S': '...', 'T': '-', 'U': '..-', | |
'V': '...-', 'W': '.--', 'X': '-..-', | |
'Y': '-.--', 'Z': '--..', | |
'0': '-----', '1': '.----', '2': '..---', | |
'3': '...--', '4': '....-', '5': '.....', | |
'6': '-....', '7': '--...', '8': '---..', | |
'9': '----.' | |
} | |
def get_char(morse): | |
for i in CODE: | |
if CODE[i] == morse: | |
return i | |
return '_' | |
def get_morse(char): | |
return CODE[char.upper()] | |
def pad(x): | |
if len(x) % 2 == 0: | |
return x | |
else: | |
return '0' + x | |
import string | |
alphabet = string.digits + string.ascii_lowercase | |
def enc(n, base=36): | |
out = [] | |
while n > 0: | |
n, r = divmod(n, base) | |
out.append(alphabet[r]) | |
return(''.join(reversed(out))) | |
def decode(x): | |
return pad(format(int(x, 36), 'x')).decode('hex') | |
def encode(x): | |
return ' '.join([get_morse(i) for i in x]) | |
io = zio(('morset.pwning.xxx', 11821), timeout=10000, print_read=COLORED(REPR), print_write=COLORED(REPR)) | |
while True: | |
line = io.readline() | |
ques = '' | |
if not line.strip(): continue | |
ques = decode(''.join(map(get_char, line[:-1].split(' ')))) | |
print ques | |
if 'What is the SHA256(' in ques: | |
s = ques[ques.find('SHA256(') + 7: ques.rfind(')')] | |
print s | |
x = hashlib.sha256(s).hexdigest() | |
io.writeline(encode(enc(int(x.encode('hex'), 16)))) | |
else: | |
io.interact() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment