Skip to content

Instantly share code, notes, and snippets.

@bnwlkr
Last active December 10, 2020 18:45
Show Gist options
  • Save bnwlkr/00b7a18510b446c89d831cc03adabab6 to your computer and use it in GitHub Desktop.
Save bnwlkr/00b7a18510b446c89d831cc03adabab6 to your computer and use it in GitHub Desktop.
Morse code necklace decode attempt
# https://www.reddit.com/r/morsecode/comments/k9x18w/please_help_with_this_necklace/
# tried with
# - https://github.com/dwyl/english-words/blob/master/words_alpha.txt (english)
# - https://github.com/mertemin/turkish-word-list/edit/master/words.txt (turkish)
# assuming single whole word, could try substrings as well
import unidecode
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': '--..'
}
SEQ = "......-.-.....--."
with open('words.txt', 'r') as words_f:
# convert things to ascii
words = {unidecode.unidecode(x).replace(' ', '')
for x in words_f.read().splitlines()}
def decode(curr, seq):
# remove 'and curr in words' to see all possibilities
if seq == "" and curr in words:
print(curr)
return
for letter, code in MORSE.items():
if seq.startswith(code):
decode(curr + letter, seq[len(code):])
decode("", SEQ)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment