Skip to content

Instantly share code, notes, and snippets.

@tallpeak
Created September 1, 2023 05:52
Show Gist options
  • Save tallpeak/e82af53262aa213bfd8455ee793bcdf4 to your computer and use it in GitHub Desktop.
Save tallpeak/e82af53262aa213bfd8455ee793bcdf4 to your computer and use it in GitHub Desktop.
morse code decoder, converted from perl by ChatGPT
morse = [' ', '-.-.--', '.-..-.', '', '...-..-', '', '.-...', '.----.', '-.--.', '-.--.-', '',
'.-.-.', '--..--', '-....-', '.-.-.-', '-..-.', '-----', '.----', '..---', '...--',
'....-', '.....', '-....', '--...', '---..', '----.', '---...', '-.-.-.', '', '-...-',
'', '..--..', '.--.-.', '.-', '-...', '-.-.', '-..', '.', '..-.', '--.', '....', '..',
'.---', '-.-', '.-..', '--', '-.', '---', '.--.', '--.-', '.-.', '...', '-', '..-',
'...-', '.--', '-..-', '-.--', '--..', '', '', '', '', '..--.-']
ascii_value = 32
morseAscii = {}
for m in morse:
ch = chr(ascii_value)
if m != '':
morseAscii[m] = ch
ascii_value += 1
message = "... --- ..."
decoded_message = ""
for w in message.split(" "):
if w in morseAscii:
decoded_message += morseAscii[w]
print(decoded_message)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment