Пример #1
0
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()
Пример #2
0
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("")
Пример #3
0
	def test_encoding_defualt(self):
		code = mtalk.encode('This is a test for default encoding.')
		morse_code = ('-   ....   ..   ...       ..   ...       .-       -   .'
			'   ...   -       ..-.   ---   .-.       -..   .   ..-.   .-   ..- '
			'  .-..   -       .   -.   -.-.   ---   -..   ..   -.   --.   .-.-.-'
			)
		assert_equal(code, morse_code)
Пример #4
0
	def test_encoding_binary(self):
		code = mtalk.encode('This is a test for binary encoding.')
		morse_code = ('-   ....   ..   ...       ..   ...       .-       -   .'
			'   ...   -       ..-.   ---   .-.       -...   ..   -.   .-   .-.'
			'   -.--       .   -.   -.-.   ---   -..   ..   -.   --.   .-.-.-'
			)
		assert_equal(code, morse_code)
Пример #5
0
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()
Пример #6
0
 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)
Пример #7
0
 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)
Пример #8
0
 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)
Пример #9
0
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)
Пример #10
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)
Пример #11
0
 def test_encode_binary2(self):
     message = 'MORSE CODE'
     binary = mtalk.encode(message, encoding_type='binary')
     binary_expected = ('11101110001110111011100010111010001010100010000000'
         '111010111010001110111011100011101010001')
     assert_equal(binary, binary_expected)
Пример #12
0
 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)
Пример #13
0
 def test_encode_morse1(self):
     message = 'MORSE CODE'
     morse_code = mtalk.encode(message)
     morse_code_expected = "--   ---   .-.   ...   .       -.-.   ---   -..   ."
     assert_equal(morse_code, morse_code_expected)
Пример #14
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))))