Skip to content

Instantly share code, notes, and snippets.

@micahhausler
Created April 5, 2017 13:11
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 micahhausler/3c177c19c30d04795c3a68062440659b to your computer and use it in GitHub Desktop.
Save micahhausler/3c177c19c30d04795c3a68062440659b to your computer and use it in GitHub Desktop.
Morse Code Decrypter
# See https://itunes.apple.com/us/app/medium/id828256236?mt=8, version 2.48
morse = {
".-": "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", "-----": "0", ".----": "1", "..---": "2", "...--": "3", "....-": "4",
".....": "5", "-....": "6", "--...": "7", "---..": "8", "----.": "9", "/": " ", ".-.-.-": ".",
".----.": "'", "--..--": ","}
text = (
'- .... .. ... / ..- .--. -.. .- - . / -- .- .. -. .-.. -.-- / -.-. --- -. - .- .. -. ... /'
' ... --- -- . / ..-. . .- - ..- .-. . / . -. .... .- -. -.-. . -- . -. - ... / .- -. -.. /'
' ..-. .. -..- . ... / ..-. --- .-. / --- ..- .-. / -. --- - / ... --- / ... . -.-. .-. . - /'
' -- . -- -... . .-. ... .... .. .--. .-.-.- / .-- . / .--. ..- - / .. - / .. -. /'
' -- --- .-. ... . / -.-. --- -.. . / -... . -.-. .- ..- ... . / -- . -- -... . .-. ... .... .. .--. /'
' .... .- ... -. .----. - / -... . . -. / .-- .. -.. . .-.. -.-- / .-. . .-.. . .- ... . -.. /'
' -.-- . - .-.-.- / -- . -.. .. ..- -- / -- . -- -... . .-. ... / .-- .. .-.. .-.. / --. . - /'
' - .... . / .-. . -.. . ... .. --. -. . -.. / .... --- -- . .--. .- --. . /'
' .-.. .- -.-- --- ..- - / .- -. -.. / .- -.. -.. .. - .. --- -. .- .-.. /'
' -- . -- -... . .-. ... .... .. .--. / -... .- -.. --. .. -. --. / .- - /'
' -- --- .-. . / .--. .-.. .- -.-. . ... / .. -. / - .... . / .- .--. .--. --..-- /'
' .--. .-.. ..- ... / .. - / ..-. .. -..- . ... / .- / -... ..- --. / .- ..-. ..-. . -.-. - .. -. --. /'
' - .... . / -. . .-- / .-. . .- -.. .. -. --. / .-.. .. ... - / - --- --- .-.. .-.-.- /'
' .- -.. -.. .. - .. --- -. .- .-.. .-.. -.-- / - .... . .-. . / .- .-. . / ... --- -- . /'
' -... ..- --. / ..-. .. -..- . ... / .- -. -.. / .--. . .-. ..-. --- .-. -- .- -. -.-. . /'
' . -. .... .- -. -.-. . -- . -. - ... / - --- / .. -- .--. .-. --- ...- . / - .... . /'
' --- ...- . .-. .- .-.. .-.. / .... . .- .-.. - .... / --- ..-. / - .... . / .- .--. .--. .-.-.- /'
' -... . / ... ..- .-. . / - --- / -.. .-. .. -. -.- / -.-- --- ..- .-. / --- ...- .- .-.. - .. -. . .-.-.-'
)
print(''.join([morse[w] for w in text.split(' ')]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment