Last active
June 1, 2018 03:00
-
-
Save yubessy/d620ed75f607c61181ab59a7a648415a to your computer and use it in GitHub Desktop.
decrypt_morse
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
MORSE_SIGNS = { | |
"a": ".-", "b": "-...", "c": "-.-.", "d": "-..", "e": ".", "f": "..-.", | |
"g": "--.", "h": "....", "i": "..", "j": ".---", "k": "-.-", "l": ".-..", | |
"m": "--", "n": "-.", "o": "---", "p": ".--.", "q": "--.-", "r": ".-.", | |
"s": "...", "t": "-", "u": "..-", "v": "...-", "w": ".--", "x": "-..-", | |
"y": "-.--", "z": "--..", | |
} | |
def decrypt_morse(morse): | |
if morse == '': | |
return [''] | |
results = [] | |
for alp, sign in MORSE_SIGNS.items(): | |
if morse.startswith(sign): | |
rest = morse[len(sign):] | |
rest_decs = decrypt_morse(rest) | |
for rest_dec in rest_decs: | |
results.append(alp + rest_dec) | |
return results | |
morse = input('input your morse> ') | |
print("input: {}".format(morse)) | |
results = decrypt_morse(morse) | |
print("# of results: {}".format(len(results))) | |
print("raw results:") | |
for res in results: | |
print(res) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment