Skip to content

Instantly share code, notes, and snippets.

@zTrix
Created Apr 19, 2016
Embed
What would you like to do?
morset writeup
#!/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