Created
June 5, 2020 04:02
-
-
Save karmanyaahm/d170222af4e39b41861a84039a1dee04 to your computer and use it in GitHub Desktop.
Fractionated morse code decoder in python3.8 (orignally made for Morbit Cipher)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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