def main(): parser = argparse.ArgumentParser(description='Send morse code') parser.add_argument('-m', '--message', help='Message', default='SOS') parser.add_argument('-d', '--duration', help='Element duration', default=None, type=float) parser.add_argument('-s', '--speed', help="Speed in wpm (Words per minutes)", default=None, type=float) parser.add_argument('--with-sound', dest='sound', help="With sound", action='store_true') parser.add_argument('--with-led', dest='led', help="With LED connected to GPIO", action='store_true') parser.add_argument('--pin-out', dest='pin_out', help="GPIO pin number on which LED is connected", default=13, type=int) args = parser.parse_args() message = args.message element_duration = args.duration wpm = args.speed print("text : %r" % message) print("morse: %s" % mtalk.encode(message)) print("bin : %s" % mtalk.encode(message, encoding_type='binary')) print("") element_duration = _get_element_duration(element_duration, wpm) if args.sound: app = ListenableSampleGeneratorApp(message, element_duration) elif args.led: import pingo from pingo.parts.led import Led board = pingo.detect.get_board() led_pin = board.pins[args.pin_out] led = Led(led_pin) app = LedSampleGeneratorApp(message, element_duration, led=led) else: app = PrintableSampleGeneratorApp(message, element_duration) app.run()
def display(message, wpm, element_duration, word_ref, strip=False): """ Display text message morse code binary morse code """ fmt = "{0:>8s}: '{1}'" key = "text" if strip: print(fmt.format(key, message.strip())) else: print(fmt.format(key, message.strip())) print(fmt.format("morse", mtalk.encode(message, strip=strip))) print(fmt.format("bin", mtalk.encode(message, encoding_type='binary', strip=strip))) print("") print("{0:>8s}:".format("timing")) print(_timing_representation(message)) print("") print("{0:>8s}:".format("spoken reprentation")) print(_spoken_representation(message)) print("") print("code speed : %s wpm" % wpm) print("element_duration : %s s" % element_duration) print("reference word : %r" % word_ref) print("")
def display(message, wpm, element_duration, word_ref, strip=False): """ Display text message morse code binary morse code """ fmt = "{0:>8s}: '{1}'" key = "text" if strip: print(fmt.format(key, message.strip())) else: print(fmt.format(key, message.strip())) print(fmt.format("morse", mtalk.encode(message, strip=strip))) print( fmt.format("bin", mtalk.encode(message, encoding_type='binary', strip=strip))) print("") print("{0:>8s}:".format("timing")) print(_timing_representation(message)) print("") print("{0:>8s}:".format("spoken reprentation")) print(_spoken_representation(message)) print("") print("code speed : %s wpm" % wpm) print("element_duration : %s s" % element_duration) print("reference word : %r" % word_ref) print("")
def main(): parser = argparse.ArgumentParser(description='Send morse code') parser.add_argument('--msg', help='Message', default='MORSE CODE') parser.add_argument('--duration', help='Element duration', default=1) args = parser.parse_args() message = args.msg duration = float(args.duration) #import datetime #duration = datetime.timedelta(seconds=0.15) # ToFix print(message) print(mtalk.encode(message)) print(mtalk.encode(message, encoding_type='binary')) ax = plotter.plot(message, duration) plt.show()
def test_encoding_defualt(self): code = mtalk.encode('This is a test for default encoding.') morse_code = ('- .... .. ... .. ... .- - .' ' ... - ..-. --- .-. -.. . ..-. .- ..- ' ' .-.. - . -. -.-. --- -.. .. -. --. .-.-.-' ) assert_equal(code, morse_code)
def test_encoding_binary(self): code = mtalk.encode('This is a test for binary encoding.') morse_code = ( '- .... .. ... .. ... .- - .' ' ... - ..-. --- .-. -... .. -. .- .-.' ' -.-- . -. -.-. --- -.. .. -. --. .-.-.-') assert_equal(code, morse_code)
def test_encoding_binary(self): code = mtalk.encode('This is a test for binary encoding.') morse_code = ('- .... .. ... .. ... .- - .' ' ... - ..-. --- .-. -... .. -. .- .-.' ' -.-- . -. -.-. --- -.. .. -. --. .-.-.-' ) assert_equal(code, morse_code)
def send(self, data, morse=False, threaded=False): if not morse: data = mtalk.encode(data) if threaded: send_morse_bg = Thread(target=self._out, args=(data, )) return send_morse_bg else: self._out(data)
def test_encode_morse2(self): message = 'Alpha Ranger 45 departed' morse_code = mtalk.encode(message) morse_code_expected = ( ".- .-.. .--. .... .- " ".-. .- -. --. . .-. ....- ..... -.. . .--. .- .-. - . -.." ) assert_equal(morse_code, morse_code_expected)
def test_encoding_default(self): message = 'This is a test for default encoding.' message = message.upper() morse_code = mtalk.encode(message) morse_code_expected = ('- .... .. ... .. ... .- - .' ' ... - ..-. --- .-. -.. . ..-. .- ..- ' ' .-.. - . -. -.-. --- -.. .. -. --. .-.-.-') assert_equal(morse_code, morse_code_expected)
def test_encoding_defualt(self): code = mtalk.encode('This is a test for default encoding.') morse_code = ( '- .... .. ... .. ... .- - .' ' ... - ..-. --- .-. -.. . ..-. .- ..- ' ' .-.. - . -. -.-. --- -.. .. -. --. .-.-.-' ) assert_equal(code, morse_code)
def encode(): global dc x = e1.get() q = mtalk.encode(x) if q != dc: dc = q e3.delete(0, END) e3.insert(0, q) e3.after(500, encode)
def test_encode_binary(self): message = 'Alpha Ranger 45 knocked down' binary = mtalk.encode(message, encoding_type='binary') binary_expected = ('10111000101110101000101110111010001010101000101110000000' '10111010001011100011101000111011101000100010111010000000' '10101010111000101010101000000011101011100011101000111011' '10111000111010111010001110101110001000111010100000001110' '1010001110111011100010111011100011101') assert_equal(binary, binary_expected)
def test_encoding_binary(self): message = 'This is a test for binary encoding.' message = message.upper() morse_code = mtalk.encode(message) morse_code_expected = ( '- .... .. ... .. ... .- - .' ' ... - ..-. --- .-. -... .. -. .- .-.' ' -.-- . -. -.-. --- -.. .. -. --. .-.-.-') assert_equal(morse_code, morse_code_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 _char_to_string_morse(c, align=ALIGN.CENTER, padding=' '): """ >>> _char_to_string_morse('O') ' O ' """ s_bin = mtalk.encode(c, encoding_type='default', letter_sep=' ') N = len(s_bin) if align == ALIGN.LEFT: s_align = "<" elif align == ALIGN.RIGHT: s_align = ">" elif align == ALIGN.CENTER: s_align = "^" else: raise NotImplementedError("align '%s' not allowed" % align) s = "{0:" + padding + s_align + str(N) + "}" return s.format(c)
def morse_code(relay_list): global DELAY DELAY = 0.400 relay_count = len(relay_list) phrase = random.choice([ 'epstein didnt kill himself', 'help kidnapped by santa', 'satan rules', 'thinkin bout thos beans' ]) morse_code = mtalk.encode(phrase, encoding_type='binary') morse_code = ('0' * relay_count) + morse_code + ('0' * relay_count) for index in range(len(morse_code) - relay_count): display_window = morse_code[index:index + relay_count] for x, segment in enumerate(display_window): if segment == '0': relay_list[x].off() elif segment == '1': relay_list[x].on() time.sleep(DELAY)
def encode_pulses(line): # Convert line to morse code binary encoding bin_enc = mtalk.encode(line.strip(), encoding_type='binary') # Convert binary encoding to a pulse sequence. We can just use something dumb for the timestamps for now. timestamps = [0] prev_value = bin_enc[0] assert (prev_value[0] == '1') for i, value in enumerate(bin_enc[1:], 1): if value != prev_value: prev_value = value timestamps.append(i) # Add the timestamp of the last falling edge timestamps.append(i + 1) # Group in pairs and create a pulse sequence timestamps = [iter(timestamps)] * 2 return [Pulse(x, y) for (x, y) in zip(*timestamps)]
import pyautogui import morse_talk as mtalk #word to convert txt = input("Enter your text:") #converts txt to morse code as binary string mcode = mtalk.encode(txt, encoding_type='binary') print(mcode) #typecasts string to list mcode = list(mcode) print(mcode) mcode_lnth = len(mcode) for i in range(mcode_lnth): # Use `xrange` for python 2. if "1" in mcode[i]: pyautogui.press('capslock') print("pressing 1") elif "0" in mcode[i]: pyautogui.press('numlock') print("pressing 0") pyautogui.press('capslock') pyautogui.press('numlock') print("loop done")
def test_encode_morse1(self): message = 'MORSE CODE' morse_code = mtalk.encode(message) morse_code_expected = "-- --- .-. ... . -.-. --- -.. ." assert_equal(morse_code, morse_code_expected)
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)
#!/usr/bin/env python import RPi.GPIO as gpio import morse_talk as mtalk import time from random import seed, randint FLICKER_PIN = 3 MESSAGE = "Resistance is futile. Have a nice day." SEQUENCE = mtalk.encode(MESSAGE, encoding_type = 'binary') CHAR_NDX = -1 seed() # ----------------------------------- gpio.setmode(gpio.BOARD) gpio.setup(FLICKER_PIN, gpio.OUT) def low(): gpio.output(FLICKER_PIN, gpio.LOW) def high(): gpio.output(FLICKER_PIN, gpio.HIGH) def nextChar(): global CHAR_NDX CHAR_NDX += 1 if (CHAR_NDX >= len(MESSAGE)): CHAR_NDX = 0
def response(self, query, message): query = query.replace('_', '-') if self.is_morse(query): return morse_talk.decode(query) else: return morse_talk.encode(query)
def test_encode_binary2(self): message = 'MORSE CODE' binary = mtalk.encode(message, encoding_type='binary') binary_expected = ('11101110001110111011100010111010001010100010000000' '111010111010001110111011100011101010001') assert_equal(binary, binary_expected)
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 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))))
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 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 paramorse(text): print(mtalk.encode(text))
def test_encode_morse2(self): message = 'Alpha Ranger 45 departed' morse_code = mtalk.encode(message) morse_code_expected = (".- .-.. .--. .... .- " ".-. .- -. --. . .-. ....- ..... -.. . .--. .- .-. - . -..") assert_equal(morse_code, morse_code_expected)
def parabin(text): print(mtalk.encode(text, encoding_type='binary'))
#!/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))))