Created
April 16, 2021 13:47
-
-
Save jgrahamc/e8fff36fbc67437e8028f3246267c7c1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
code = { | |
'01': 'A', | |
'1000': 'B', | |
'1010': 'C', | |
'100': 'D', | |
'0': 'E', | |
'0010': 'F', | |
'110': 'G', | |
'0000': 'H', | |
'00': 'I', | |
'0111': 'J', | |
'101': 'K', | |
'0100': 'L', | |
'11': 'M', | |
'10': 'N', | |
'111': 'O', | |
'0110': 'P', | |
'1101': 'Q', | |
'010': 'R', | |
'000': 'S', | |
'1': 'T', | |
'001': 'U', | |
'0001': 'V', | |
'011': 'W', | |
'1001': 'X', | |
'1011': 'Y', | |
'1100': 'Z', | |
'01111': '1', | |
'00111': '2', | |
'00011': '3', | |
'00001': '4', | |
'00000': '5', | |
'10000': '6', | |
'11000': '7', | |
'11100': '8', | |
'11110': '9', | |
'11111': '0' | |
} | |
def morse(b): | |
r = [] | |
for p in code: | |
if b.startswith(p): | |
for i in morse(b[len(p):]): | |
r.append(code[p] + i) | |
if len(r) == 0: | |
return [b] | |
else: | |
return r | |
def clean(m): | |
return [i for i in m if 'EE' not in i and 'TT' not in i and 'MM' not in i] | |
for c in range(33, 127): | |
b = format(c, '08b') | |
print('\n'.join(clean(morse(b)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
So, suppose you wanted to encode each printable ASCII character in Morse code by have dot = 0 and dah = 1 and be able to interpret the resulting Morse code as both the ASCII character and a word in Morse code. Don't ask why, just suppose you needed to do that.
Well, here's a little program that prints out every "word" possible by splitting up the binary representation of each printable ASCII character into different Morse code letters in as many ways as possible.
For example,
ASCII L is 01001100 which is . - . . - - . . which can be broken into . / - . . / - - . / . which is EDGE. Thus . / - . . / - - . / . could be interpreted as EDGE or L.