Skip to content

Instantly share code, notes, and snippets.

@karmanyaahm
Created June 5, 2020 04:02
Show Gist options
  • Save karmanyaahm/d170222af4e39b41861a84039a1dee04 to your computer and use it in GitHub Desktop.
Save karmanyaahm/d170222af4e39b41861a84039a1dee04 to your computer and use it in GitHub Desktop.
Fractionated morse code decoder in python3.8 (orignally made for Morbit Cipher)
#derived from code by geeksforgeeks by karmanyaahm
MORSE_CODE_DICT = { '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':'--..',
'1':'.----', '2':'..---', '3':'...--',
'4':'....-', '5':'.....', '6':'-....',
'7':'--...', '8':'---..', '9':'----.',
'0':'-----', ', ':'--..--', '.':'.-.-.-',
'?':'..--..', '/':'-..-.', '-':'-....-',
'(':'-.--.', ')':'-.--.-'
}
def decrypt(message,symbol=' '):
message += 'x'
decipher = ''
temp = ''
num = 0
while(num<len(message)):
value = message[num]
if value =='.' or value == '-':
temp+=value
elif (value == symbol):
if (message[num-1]==symbol):
decipher += ' '
elif (message[num-1]!=symbol):
try:
decipher += list(MORSE_CODE_DICT.keys())[list(MORSE_CODE_DICT.values()).index(temp)]
except:
decipher+='#'#means idk
temp = ''
else:
raise Exception
else:
raise Exception
num+=1
return decipher
print(decrypt('.-..x---x.-..x---x.-..x---x.-..x---x.-..x---x.-..xx.-..x---x.-..x---x.-..','x'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment