import pandas
morse_data = pandas.read_csv("morse_code.csv")
print(morse_data)
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 Encryptor(characters):
encrypted = ""
for letter in characters:
if letter != " ":
encrypted = encrypted + MORSE_CODE_DICT.get(letter) + " "
else:
encrypted = encrypted + " "
print(encrypted)
Morse()
def Decryptor(text):
key_list = list(MORSE_CODE_DICT.keys())
val_list = list(MORSE_CODE_DICT.values())
space_found = 0
morse = ""
normal = ""
for letter in text:
if letter != " ":
morse += letter
space_found = 0
else:
space_found += 1
if space_found == 2:
normal = normal + " "
else:
normal = normal + key_list[val_list.index(morse)]
morse = ""
print(normal)
Morse()
print("\nMorse Code Generator!")
def Morse():
ch = input("Enter 'e' or 'E' to Encrypt or 'd' or 'D' to Decrypt message: ")
if ch == "E" or ch == "e":
text_to_encrypt = input("Enter your text to Encrypt message! ").upper()
Encryptor(text_to_encrypt)
elif ch == "D" or ch == "d":
text_to_decrypt = input("Enter the text to Encrypt message! ").upper()
Decryptor(text_to_decrypt)
#Important Note: You will need to click the link to download the file or create your own nato.csv file.