示例#1
0
文件: mdbc.py 项目: pdogg/mdbc
def makeItRain(ciphertext):
	print "Cry \'Havoc!\', and let slip the dogs of war"
	print "Shift Cipher:"
	shift.bruteForce(ciphertext)
	print "\nAffine Cipher:"
	affine.bruteForce(ciphertext)
	print "\nAtbash :"
	print atbash.decrypt(ciphertext)
	print "\nMorse Code:"
	print morse.encode(ciphertext)
示例#2
0
文件: test.py 项目: cy-xu/morse
 def test_strencode_decode_exaustive(self):
     '''Evil test'''
     all_chr = [chr(i) for i in range(256)]
     many_chr = all_chr * 4 + list('        ') * 32
     random.shuffle(many_chr)
     phrase = "".join(many_chr)
     expected_decode = morse.removeunusablecharacters(phrase).lower()
     encoded = morse.encode(phrase)
     decoded = morse.decode(encoded)
     self.assertEqual(expected_decode, decoded.lower())
示例#3
0
 def test_strencode_decode_exaustive(self):
     '''Evil test'''
     all_chr = [chr(i) for i in range(256)]
     many_chr = all_chr * 4 + list('        ') * 32
     random.shuffle(many_chr)
     phrase = "".join(many_chr)
     expected_decode = morse.removeunusablecharacters(phrase).lower()
     encoded = morse.encode(phrase)
     decoded = morse.decode(encoded)
     self.assertEqual(expected_decode, decoded.lower())
示例#4
0
文件: led.py 项目: Geekfish/duth
def morse_led(message, dry_run=False):
    assert len(message) <= LED_RANGE[-1]
    colour_map = {
        '.': "1FE0E0",
        '-': "1F4CE0",
        '/': "FFFFFF",
        ' ': "000000",
    }

    morse_msg = encode(message)
    for led_index, char in enumerate(morse_msg):
        update_led(led_index, colour_map[char], dry_run)
示例#5
0
文件: issue1.py 项目: sashastds/aaa
def test_encode(message: str) -> str:
    """
    >>> test_encode(message='SOS')
    '... --- ...'
    >>> test_encode(message='')
    ''
    >>> test_encode(message='OSOSO') #doctest: +ELLIPSIS
    '---...---'
    >>> test_encode(message='SOS' * 20) 
    '... --- ... ... --- ... ... --- ... ... --- ... ... --- ... ... --- ... ... --- ... ... --- ... ... --- ... ... --- ...
    ... --- ... ... --- ... ... --- ... ... --- ... ... --- ... ... --- ... ... --- ... ... --- ... ... --- ... ... --- ...'
    >>> test_encode(message='sos')
    Traceback (most recent call last):
    ...
    KeyError: 's'
    """
    from morse import encode

    return encode(message)
示例#6
0
文件: image.py 项目: cy-xu/morse
def draw(string, file):

    if "." not in string or "-" not in string or "/" not in string or "//" not in string:
        string = morse.encode(string)

    words = string.split("//")

    i = []
    for word in words:
        letters = word.split("/")

        for letter in letters:
            charletter = list(letter)
            for x in charletter:
                if x == ".":
                    i.append(1)
                elif x == "-":
                    i.append(1)
                    i.append(1)
                    i.append(1)
                else:
                    continue
                i.append(0)
            i.append(0)
            i.append(0)
        #draw.line((i,0,i+7,0), fill=0)
        i.append(0)
        i.append(0)
        i.append(0)
        i.append(0)

    while i[-1] == 0:
        i.pop()

    im = Image.new("1", (len(i), 1))
    im.putdata(i)
    im.save(file, "PNG")
示例#7
0
文件: image.py 项目: cndeng/morse-1
def draw(string, file):

    if "." not in string or "-" not in string or "/" not in string or "//" not in string:
        string = morse.encode(string)
    
    words = string.split("//")

    i = []
    for word in words:
        letters = word.split("/")

        for letter in letters:
            charletter = list(letter)
            for x in charletter:
                if x == ".":
                    i.append(1)   
                elif x == "-":
                    i.append(1)
                    i.append(1)
                    i.append(1)
                else:
                    continue
                i.append(0)
            i.append(0)
            i.append(0)
        #draw.line((i,0,i+7,0), fill=0)
        i.append(0)
        i.append(0)
        i.append(0)
        i.append(0)

    while i[-1] == 0:
        i.pop()
    
    im = Image.new("1", (len(i),1))
    im.putdata(i)
    im.save(file, "PNG")
示例#8
0
import morse

message = 'sos ahahahaha'

code = morse.encode(message)
decode = morse.decode(code)

print(message == decode)
示例#9
0
文件: test.py 项目: cy-xu/morse
 def test_encode(self):
     '''Test encoding and decoding of normal charaters'''
     phrase = "The quick red fox jumped over the lazy dog 1234567890"
     encoded = morse.encode(phrase)
     decoded = morse.decode(encoded)
     self.assertEqual(phrase.lower(), decoded.lower())
示例#10
0
def test_roundtrip_morse(morse):
    morse_message = ' '.join(morse)
    assert encode(decode(morse_message)) == morse_message
示例#11
0
def test_encode_with_comma():
    with pytest.raises(KeyError):
        encode("SIMPLE TEXT,WITH COMMA")
示例#12
0
def test_encode_with_comma_and_space():
    with pytest.raises(KeyError):
        encode("SIMPLE TEXT, WITH COMMA AND SPACE")
示例#13
0
def test_roundtrip(text):
    assert decode(encode(text)) == text
示例#14
0
def test_encode_and_decode_funcs_are_irreversible():
    test_case = "WITH SPACE"
    assert test_case != decode(encode(test_case))
示例#15
0
 def test_encode(self):
     '''Test encoding and decoding of normal charaters'''
     phrase = "The quick red fox jumped over the lazy dog 1234567890"
     encoded = morse.encode(phrase)
     decoded = morse.decode(encoded)
     self.assertEqual(phrase.lower(), decoded.lower())
 def test_words_encode(self):
     assert encode('12 34') == self.morse_12_23
示例#17
0
from morse import decode, encode

print(encode("hello"))  # .... . .-.. .-.. ---
print(encode("candy"))  # -.-. .- -. -.. -.--
# .-- .... .- -   .. ...   -.-- --- ..- .-.   -. .- -- .
print(encode("what is your name"))

print(decode(".... ..   - .... . .-. . "))  # hi there
# we like codeday
print(decode(".-- .   .-.. .. -.- .   -.-. --- -.. . -.. .- -.-- "))
# thanks for playing
print(
    decode(
        "- .... .- -. -.- ...   ..-. --- .-.   .--. .-.. .- -.-- .. -. --. "))

# Checks, should all be true
print(encode("hello") == ".... . .-.. .-.. --- ")
print(encode("candy") == "-.-. .- -. -.. -.-- ")
print(
    encode("what is your name") ==
    ".-- .... .- -   .. ...   -.-- --- ..- .-.   -. .- -- . ")

print(decode(".... ..   - .... . .-. . ") == "hi there")
print(
    decode(".-- .   .-.. .. -.- .   -.-. --- -.. . -.. .- -.-- ") ==
    "we like codeday")
print(
    decode("- .... .- -. -.- ...   ..-. --- .-.   .--. .-.. .- -.-- .. -. --. "
           ) == "thanks for playing")
示例#18
0
        server_url_ = 'tcp://{}'.format(default_ip)
    try:
        server_port = int(port_)
    except (ValueError, TypeError):
        server_port = default_port
    server_url_ = '{}:{}'.format(server_url_, server_port)
    return server_url_


parser = ArgumentParser(
    description='Gets strings trough zmq, '
                'translates it to morse code '
                'and sends impulses trough GPIO',
)
parser.add_argument('address', nargs='?')
parser.add_argument('port', nargs='?')
args = parser.parse_args()
address = args.address
port = args.port
server_url = parse_address(address, port)

context = zmq.Context()
socket = context.socket(zmq.SUB)
socket.setsockopt(zmq.SUBSCRIBE, 'Morse')
socket.connect(server_url)
while True:
    payload = socket.recv()
    topic, message = payload.split()
    print(morse.encode(message))
    pi.send_morse_to_pi(morse.encode(message))
示例#19
0
def test_sos():
    assert encode('sos') == '... --- ...'
示例#20
0
    if all([i in '-. 01' for i in intext]):
        temptext = transcript_method.decode(intext)
        print("EN: ", temptext)

        temptext = temptext.replace(" ", "")

        if temptext.isalnum():
            # 每隔 4 个字符分割一下
            splited = [
                temptext[i * 4:i * 4 + 4] for i in range(len(temptext) // 4)
            ]
            try:
                outtext = [decode_table[i] for i in splited]
                print("CN: ", ''.join(outtext))
            except:
                # 查不到?忽略忽略
                pass
    else:
        if all([i in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789' for i in intext]):
            print("EN: ", morse.encode(intext))
        elif all([
                i in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 -@$!&#\'()"/:;?,.'
                for i in intext
        ]):
            print("EN: ", ita2.encode(intext))
        else:
            temptext = ''.join([encode_table[i] for i in intext])

            print("CN: ", transcript_method.encode(temptext))
 def test_sos_encode(self):
     assert encode('SOS') == self.morse_sos