def test_decoding_default(self): code = ('- .... .. ... .. ... .- - .' ' ... - ..-. --- .-. -.. . ..-. .- ..- ' ' .-.. - . -. -.-. --- -.. .. -. --. .-.-.-') message = mtalk.decode(code) message_expected = 'THIS IS A TEST FOR DEFAULT ENCODING.' assert_equal(message, message_expected)
def test_decoding_default(self): code = ('- .... .. ... .. ... .- - .' ' ... - ..-. --- .-. -.. . ..-. .- ..- ' ' .-.. - . -. -.-. --- -.. .. -. --. .-.-.-' ) message = mtalk.decode(code) assert_equal(message, 'this is a test for default encoding.')
def test_decoding_default(self): code = ( '- .... .. ... .. ... .- - .' ' ... - ..-. --- .-. -.. . ..-. .- ..- ' ' .-.. - . -. -.-. --- -.. .. -. --. .-.-.-' ) message = mtalk.decode(code) assert_equal(message, 'this is a test for default encoding.')
def test_decoding_default(self): code = ('- .... .. ... .. ... .- - .' ' ... - ..-. --- .-. -.. . ..-. .- ..- ' ' .-.. - . -. -.-. --- -.. .. -. --. .-.-.-' ) message = mtalk.decode(code) message_expected = 'THIS IS A TEST FOR DEFAULT ENCODING.' assert_equal(message, message_expected)
def morse(content): if content >= u'\u4e00' and content <= u'\u9fff': reply = u'摩斯密码只支持英文和数字' else: try: reply = mtalk.decode(content) reply = '摩尔斯密码解码为:%s' % reply except KeyError: reply = mtalk.encode(content) reply = '摩尔斯密码编码为:%s' % reply return reply
def decode(): global cd global y if e2.get() == '': y = "a" else: y = e2.get() r = '' if y[-1] == ' ': r = mtalk.decode(y) if r != cd: cd = r e4.delete(0, END) e4.insert(0, r) e4.after(500, decode)
def decode(code): for i in range(1, 5): try: base = morse_talk.decode(code[:i]) if len(code[i:]) == 0: yield base break else: for rest in decode(code[i:]): yield '%s%s' % (base, rest) except KeyError: break
def decode_pulses(pulses): pulses, gaps = classify_pulses(pulses) assert (len(pulses) == len(gaps) + 1) binary_encoding = [] for x, y in zip(pulses[:-1], gaps): binary_encoding.extend([1] * x) binary_encoding.extend([0] * y) binary_encoding.extend([1] * pulses[-1]) try: return mtalk.decode(''.join(map(str, binary_encoding)), encoding_type='binary') except KeyError: print(binary_encoding) return 'Err: decode failure'
def decode_pulses(pulses): min_duration = min(p.duration() for p in pulses) binary_encoding = [] prev_pulse = None for p in pulses: if prev_pulse is not None: gap_width = p.on - prev_pulse.off binary_encoding.extend([0] * gap_width) pulse_width = p.duration() // min_duration binary_encoding.extend([1] * pulse_width) prev_pulse = p return mtalk.decode(''.join(map(str, binary_encoding)), encoding_type='binary')
def bruteforce(string): results = {} # BASES base = { 16: b16decode, 32: b32decode, 58: b58decode, 64: b64decode, 85: b85decode } for i in base.keys(): try: results['b' + str(i)] = base[i](string) except: pass # print("error base: "+str(i)) # MORSE try: results['morse'] = mtalk.decode(string) except Exception as e: pass # HEX try: results['hex'] = bytearray.fromhex(string).decode() except Exception as e: pass # BINARY, OCTAL, DECIMAL for base in [2, 8, 10]: try: results['base-' + str(base)] = "".join( [chr(int(i, base=base)) for i in string.split()]) except Exception as e: pass print() pprint.pprint(results) print()
def test_decode_morse(self): morse = '-... --- -- -... -..- .--. --' message = mtalk.decode(morse) message_expected = 'BOMB X PM' assert_equal(message, message_expected)
#!/usr/bin/env python3 import morse_talk as mtalk msg1 = 'XYYY YXXX XYXX XXY XYY X XYY YX YYXX'.replace('X', '.').replace('Y', '-') msg1 = mtalk.decode(msg1) def CaesarDecode(msg, shift): UpperTable = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' LowerTable = 'abcdefghijklmnopqrstuvwxyz' m = [] for i in range(len(msg)): if msg[i].isalpha(): if msg[i].islower(): index = ord(msg[i]) - ord('a') m.append(LowerTable[(index - shift) % 26]) else: index = ord(msg[i]) - ord('A') m.append(UpperTable[(index - shift) % 26]) else: m.append(msg[i]) return ''.join(m) print('PCTF{%s}' % CaesarDecode(msg1, 20))
def handle(msg): content_type, chat_type, chat_id = telepot.glance(msg) global machine_state str_testo_morse = "" str_testo_alphabet = "" chat_id = msg['chat']['id'] command_input = msg['text'] print(chat_id, content_type) if machine_state == 0 and content_type == 'text': if command_input == '/start' or command_input == '/start@MorsetorBot': start_text = '''Benvenuto nel futuro! Inizia a digitare un comando per cominciare un'esperienza metafisica''' bot.sendMessage(chat_id, start_text) machine_state = 1 elif machine_state == 1 and content_type == 'text': if command_input == '/help' or command_input == '/help@FrazionetorBot': help_text = "Salve, puoi inizare a utilizzare il comando /atm per convertire un qualsiasi " help_text += "messaggio in codice Morse mentre puoi utilizzare il comando /mta per convertire un codice Morse " help_text += "in un messaggio di testo.\nPuoi contattare lo sviluppatore su github.com/Azzeccagarbugli" bot.sendMessage(chat_id, help_text) machine_state = 1 elif command_input == '/atm' or command_input == '/atm@FrazionetorBot': morse_text = "Inserisci il messaggio che vuoi convertire in codice Morse" bot.sendMessage(chat_id, morse_text) machine_state = 2 elif command_input == '/mta' or command_input == '/mta@FrazionetorBot': alphabet_text = "Inserisci il codice Morse che vuoi convertire in un messagio" bot.sendMessage(chat_id, alphabet_text) machine_state = 3 else: problem_text = "Non hai inserito un comando valido, riprova" bot.sendMessage(chat_id, problem_text) machine_state = 1 elif machine_state == 2 and content_type == 'text': str_testo_morse = command_input.lower() str_morse = mtalk.encode(str_testo_morse) str_answer_morse = ( "Il messaggio convertito in codice Morse è: {0}".format(str_morse)) bot.sendMessage(chat_id, str_answer_morse, parse_mode="Markdown") print(str_answer_morse) machine_state = 1 elif machine_state == 3 and content_type == 'text': try: str_testo_alphabet = str(command_input.lower()) str_alphabet = mtalk.decode(str_testo_alphabet) str_answer_alphabet = ( "Il messaggio convertito in lingua comprensibile è: {0}". format(str_alphabet)) bot.sendMessage(chat_id, str_answer_alphabet, parse_mode="Markdown") print(str_answer_alphabet) machine_state = 1 except: str_alphabet_problem = "Non è stato possibile convertire il messaggio in una lingua comprensibile" bot.sendMessage(chat_id, str_alphabet_problem) machine_state = 1
import binascii import morse_talk as mtalk toprint = mtalk.decode( '..-. .-.. .- --. ... .- -- ..- . .-.. -- --- .-. ... . .. ... -.-. --- --- .-.. -... -.-- - .... . .-- .- -.-- .. .-.. .. -.- . -.-. .... . . ...' ) print(toprint) # n = int("01000011010101000100011001111011010000100110100101110100010111110100011001101100011010010111000001110000011010010110111001111101", 2) # binascii.unhexlify('%x' % n) # s = "01000011010101000100011001111011010000100110100101110100010111110100011001101100011010010111000001110000011010010110111001111101" # s = str(hex(int(s, 2)))[2::] # o = [] # while s: # o.append(s[:2]) # s = s[2:] # for letter in o: # print(chr(int(letter, 16)), end="")
#!/usr/bin/env python2 from pwn import * from morse_talk import decode, encode import binascii import hashlib from base36 import base36decode, base36encode r = remote("morset.pwning.xxx", 11821) p = r.recv() print binascii.unhexlify("0{:02x}".format(base36decode(decode(p)))) temp = binascii.unhexlify("0{:02x}".format(base36decode( decode(p)))).split("SHA256(")[1][:-2] print "to hash is: %s" % temp h = hashlib.new("sha256") h.update(temp) print "hexdigest: %s" % h.hexdigest() print "hexlified: %s" % binascii.hexlify(h.hexdigest()) print "base36ed: %s" % base36encode(int(binascii.hexlify(h.hexdigest()), 16)) r.sendline(encode(base36encode(int(binascii.hexlify(h.hexdigest()), 16)))) import time time.sleep(1) rep = r.recv().rstrip().strip() print "rep is: %s" % rep print binascii.unhexlify("{:02x}".format(base36decode(decode(rep))))
import morse_talk as mtalk s = '..-. .-.. .- --. ..... ..--- ..--- ----- .---- ---.. -.. -.... -.... ..... ...-- ---.. --... -.. .---- -.. .- ----. ...-- .---- ---.. .---- ..--- -... --... --... --... -.... ...-- ....- .---- -----' ss = mtalk.decode(s) print ss[4:]
def binpara(text): print(mtalk.decode(text, encoding_type='binary'))
def response(self, query, message): query = query.replace('_', '-') if self.is_morse(query): return morse_talk.decode(query) else: return morse_talk.encode(query)
import morse_talk as mtalk import sys string = sys.argv[2] if sys.argv[1] == "-e": string = mtalk.encode(string) print(string) if sys.argv[1] == "-d": string = mtalk.decode(string) print(string) sys.exit(0)
#!/usr/bin/env python3 import morse_talk as mtalk from hashlib import md5 msg = mtalk.decode('..-. .-.. .- --. ..... ..--- ..--- ----- .---- ---.. -.. -.... -.... ..... ...-- ---.. --... -.. .---- -.. .- ----. ...-- .---- ---.. .---- ..--- -... --... --... --... -.... ...-- ....- .---- -----') print(msg[-32:])
import morse_talk as mtalk import sys string = sys.argv[2] if sys.argv[1] == "-e": string = mtalk.encode(string, encoding_type='binary') print(string) if sys.argv[1] == "-d": string = mtalk.decode(string, encoding_type='binary') print(string) sys.exit(0)
def test_decode_binary(self): message = 'MORSE CODE' binary = mtalk.encode(message, encoding_type='binary') message_decoded = mtalk.decode(binary, encoding_type='binary') assert_equal(message_decoded, message)
continue ip = eth.data if ip.p != dpkt.ip.IP_PROTO_UDP: continue udp = ip.data if 23284 not in [udp.sport, udp.dport]: continue # Check the timestamps to differentiate morse code dif = ts - last_ts if dif < 0.1: ctr += 1 elif dif > 0.48: if ctr == 6: morse += '.' elif ctr == 12: morse += '-' if dif > 1: morse += ' ' ctr = 1 last_ts = ts # Print morse and flag print morse flag = '' for i in morse.split(' '): try: flag += morse_talk.decode(i) except KeyError: flag += '?' print flag
def morsepara(text): print(mtalk.decode(text))
import morse_talk as mtalk morse = '. ----- -.... ..... ...-- .---- -.. .---- ----. ..-. ..-. ----- ..--- ----- .- ....- --... ----. ..... ..--- ----- . ..-. ..--- ---.. -.-. ---.. -.. .---- . ..--- -.-.' print('PST{' + mtalk.decode(morse).lower() + '}')
#!/usr/bin/env python2 from pwn import * from morse_talk import decode, encode import binascii import hashlib from base36 import base36decode, base36encode r = remote("morset.pwning.xxx", 11821) p = r.recv() print binascii.unhexlify("0{:02x}".format(base36decode(decode(p)))) temp = binascii.unhexlify("0{:02x}".format(base36decode(decode(p)))).split("SHA256(")[1][:-2] print "to hash is: %s" % temp h = hashlib.new("sha256") h.update(temp) print "hexdigest: %s" % h.hexdigest() print "hexlified: %s" % binascii.hexlify(h.hexdigest()) print "base36ed: %s" % base36encode(int(binascii.hexlify(h.hexdigest()),16)) r.sendline(encode(base36encode(int(binascii.hexlify(h.hexdigest()),16)))) import time; time.sleep(1) rep = r.recv().rstrip().strip() print "rep is: %s" % rep print binascii.unhexlify("{:02x}".format(base36decode(decode(rep))))