Skip to content

Instantly share code, notes, and snippets.

@yubessy
Last active Jun 1, 2018
Embed
What would you like to do?
decrypt_morse
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