import pandas
morse_data = pandas.read_csv("morse_code.csv")
nato_data = pandas.read_csv("nato.csv")
phonetic_code_dict = {row.character: row.code for (index, row) in nato_data.iterrows()}
print(f"\n{morse_data}\n")
print(f"\n{phonetic_code_dict}\n")
# Start of:Morse_Code Encryptor and Decrypter
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)
encrypt_question = input("Press 'M' or 'm' for Morse and 'N' or 'n' for Nato!")
if encrypt_question == "M" or encrypt_question == "m":
Morse()
elif encrypt_question == "N" or encrypt_question == "n":
phoneticCodeGenerator()
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)
decrypt_question = input("Press 'M' or 'm' for Morse and 'N' or 'n' for Nato!")
if decrypt_question == "M" or decrypt_question == "m":
Morse()
elif decrypt_question == "N" or decrypt_question == "n":
phoneticCodeGenerator()
def morseNatoSelection():
morse_nato_choice = input("Press 'M' or 'm' for Morse and 'N' or 'n' for Nato!")
if morse_nato_choice == "M" or morse_nato == "m":
Morse()
elif morse_nato_choice == "N" or morse_nato == "n":
phoneticCodeGenerator()
def Morse():
print("Morse Code Generator!")
ch = input("Enter 'e' or 'E' to Encrypt or 'd' or 'D' to Decrypt message: ")
if ch == "E" or ch == "e":
morse_text_to_encrypt = input("Enter your text to Encrypt message! ").upper()
Encryptor(morse_text_to_encrypt)
elif ch == "D" or ch == "d":
morse_text_to_decrypt = input("Enter the text to Encrypt message! ").upper()
Decryptor(morse_text_to_decrypt)
# End of:Morse_Code Encryptor and Decrypter
# Start of:Nato_Code Encryptor
def phoneticCodeGenerator():
print("Nato Code Generator!")
word = input("Enter a word or a phrase!").upper()
try:
output_list = [phonetic_code_dict[letter] for letter in word]
except KeyError:
print("Sorry, only characters that are in the alphabet and basic grammar marks!")
morseNatoSelection()
else:
print(output_list)
question = input("Press 'M' or 'm' for Morse and 'N' or 'n' for Nato!")
if question == "M" or question == "m":
Morse()
elif question == "N" or question == "n":
phoneticCodeGenerator()
# End of:Nato_Code Encryptor
morse_nato = input("Do you want morse or nato? Type 'M' or 'm' for Morse and 'N' or 'n' for Nato?")
if morse_nato == "M" or morse_nato == "m":
Morse()
elif morse_nato == "N" or morse_nato == "n":
phoneticCodeGenerator()
#Important Note: You will need to click the link to download the file or create your own nato.csv file.