Skip to content

Instantly share code, notes, and snippets.

@yubessy
Last active June 1, 2018 03:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yubessy/d620ed75f607c61181ab59a7a648415a to your computer and use it in GitHub Desktop.
Save yubessy/d620ed75f607c61181ab59a7a648415a to your computer and use it in GitHub Desktop.
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