def overwrite(cwd, ret): print( "\nAttention: A Message File Has Been Found. Continuing Will Overwrite This File." ) print("\n\tDo You Wish To Continue?\n\t1. Yes \n\t2. No") try: overwrite_choice = int(input("Please Select an Option: ")) except ValueError: print("\tError: Value Must Be A Number.\n") overwrite(cwd, ret) if overwrite_choice == 1: msg = input( "This Message will be converted to a text file. \nPlease Input A Message And Press \"Enter\" To Continue: " ) message_creator(msg) elif overwrite_choice == 2: if ret == 0: file_not_found_menu(cwd) elif ret == 1: file_found_menu(cwd) else: controller.main_menu() else: print("Invalid Option: Must Be 1 or 2...") overwrite(cwd, ret)
def settings_menu(code): settings = init(code) print_settings(settings, code) print("\n-----SETTINGS MENU-----") print("\n\tOptions:") print("\t1. Change Settings") print("\t2. Help") print("\t3. Return To Main Menu") print("\t4. Exit") try: settings_choice = int(input("Please Select an Option: ")) except ValueError: print("\tError: Value Must Be A Number.\n") settings_menu(code) if settings_choice == 1: change_settings(settings, code) elif settings_choice == 2: help_menu(code) settings_menu(code) elif settings_choice == 3: controller.main_menu() elif settings_choice == 4: print("Goodbye...") sys.exit(0) else: print("\nInvalid Option...") settings_menu(code)
def decode(raw, settings, alphabet_key, tones): if settings['manual'] == 'true': print("\n\n-----BEGINNING MANUAL INPUT-----\n ") decode_values = list( input( "Please Input Numerical Output Values(2-digit numbers, space seperated): " ).split()) value_list = [] msg = "" for value in decode_values: for digit in value: for key, value in tones.items(): if digit == key: value_list.append(value) for i, values in enumerate(value_list): check_list = [] if i % 2 == 0: check_list = [value_list[i], value_list[i + 1]] for key, value in alphabet_key.items(): if value == check_list: msg = msg + str(key) return msg else: print( "\n-----ERROR: AUTOMATIC DECODING CURRENTLY UNAVALIABLE. ISSUES WITH INTEFERENCE IN DECODING-----" ) controller.main_menu() # TODO: DETERMINE SOLUTION FOR AUTOMATIC DECODING return msg
def encode(settings, msg, ciphertext, low, high, tones, alphabet_key): print("-----ENCODING TO AUDIO FORMAT-----") audio = [] if ciphertext == '': ciphertext = msg for i, char in enumerate(ciphertext): key = alphabet_key[char] tone_1 = key[0] tone_2 = key[1] freq_1 = low[tone_1[0]] freq_2 = high[tone_1[1]] freq_3 = low[tone_2[0]] freq_4 = high[tone_2[1]] append_sin_wave(settings, freq_1, freq_2, audio) if not float(settings['pause']) == 0.0: append_pause(settings, audio) append_sin_wave(settings, freq_3, freq_4, audio) if not float(settings['pause']) == 0.0: append_pause(settings, audio) file_path = save_file(settings, audio) if settings['broadcast'] == 'true': print("-----PLAYING AUDIO-----") audio_file = AudioSegment.from_wav(file_path) play(audio_file) if settings['file'] == 'false': os.remove(file_path) if len(os.listdir(os.getcwd() + '/generated_audio/')) == 0: os.rmdir(os.getcwd() + '/generated_audio/') print("-----EXECUTION COMPLETE-----") controller.main_menu()
def main(): low, high, tones, alphabet_key, settings = init() print("\n-----STARTING DECODER-----") print("-----CURRENT DECODER SETTINGS-----\n") for i in settings: print(i + " = " + settings[i]) print("\n-----SETTINGS LOADED-----") cwd = os.getcwd() + '/decode_audio/' if len(os.listdir(cwd)) > 1: print("ERROR: MORE THAN ONE AUDIO FILE FOUND. \nEXITING...") sys.exit(1) if len(os.listdir(cwd)) == 0: print("\nAudio File Not Found...") print("Redirecting to File Creator") audio_file.file_not_found_menu(cwd) for f in os.listdir(cwd): file_name = (os.path.join(cwd, f)) local_file = f if settings['broadcast'] == 'true': print("-----PLAYING AUDIO-----") audio = AudioSegment.from_wav(file_name) play(audio) raw = raw_decode(file_name, settings) msg = decode(raw, settings, alphabet_key, tones) if settings['shift'] == 'true': print("\n-----SHIFTING-----\n") plaintext = shift(settings, msg, alphabet_key) else: print("\n-----FINAL OUTPUT-----") print('Plaintext: ' + plaintext) if settings['file'] == 'true': with open(os.getcwd() + "/" + local_file + "_report.txt", 'w') as f: f.write("----- DECODING REPORT OF \'" + local_file + "\' -----\n\n-----RAW_OUTPUT-----") f.write("\n\n" + raw) if settings['shift'] == 'true': f.write("\n\n-----FINAL_OUTPUT-----") f.write("\nCiphertext_Output: " + msg) f.write('\nPlaintext_Output: ' + plaintext) print("-----OUTPUT FILE CREATED-----") print("\n-----EXECUTION COMPLETE-----") controller.main_menu()
def main(): print("\n-----STARTING ENCODER-----") settings, msg = init() low, high, tones, alphabet_key = init_keys() print_settings(settings) print("\n-----SETTINGS LOADED-----") if settings['broadcast'] == 'false' and settings['file'] == 'false': print( "ERROR: 'broadcast' and 'file' variables are both false. This program will not generate any output." ) controller.main_menu() ciphertext = '' if settings['shift'] == 'true': print("-----SHIFTING-----\n") ciphertext = shift(settings, msg, ciphertext, alphabet_key) else: print('Plaintext: ' + msg) encode(settings, msg, ciphertext, low, high, tones, alphabet_key)
def main(): cwd = os.getcwd() + '/decode_audio/' if os.path.exists(cwd) and not os.path.isfile(cwd): if not os.listdir(cwd): print("\nAudio File Not Found...") file_not_found_menu(cwd) else: if len(os.listdir(cwd)) > 1: print( "\nERROR: Multiple Audio Files Found In \'decode_audio\' Folder. \nFolder Must Only Contain One File To Decode." ) controller.main_menu() else: print("\nAudio File Found...") file_found_menu(cwd) else: print("-----ERROR: DECODE_AUDIO FOLDER NOT FOUND-----") sys.exit(1)
def file_not_found_menu(cwd): ret = 0 print("\n-----FILE NOT FOUND MENU-----") print("\n\tOptions:") print("\t1. Add Message File") print("\t2. Create Message File") print("\t3. Help") print("\t4. Return To Main Menu") print("\t5. Exit") try: file_not_found_menu_choice = int(input("Please Select an Option: ")) except ValueError: print("\tError: Value Must Be A Number.\n") file_not_found_menu(cwd) if file_not_found_menu_choice == 1: input( "Halting... Please Add a Message File to the Directory.\nPress \"Enter\" To Continue..." ) main() elif file_not_found_menu_choice == 2: if os.path.isfile(cwd + '/message.txt'): overwrite(cwd, ret) else: msg = input( "This Message will be converted to a text file. \nPlease Input A Message And Press \"Enter\" To Continue: " ) message_creator(msg) controller.main_menu() elif file_not_found_menu_choice == 3: print( "\nA message file must exist in the same directory as the program. This file contains the message to be encoded. \nFrom here, you may:\n\nAdd A Message File: The program will wait. At this point, you may add your own message file to the directory. \nWhen you have done this, the program will prompt you to continue, and will rescan the directory for the message file. \n-----MESSAGE FILE MUST BE NAMED \"message.txt\"-----\n\nCreate A Message File: The program will create a message file for you, using input given from the command line.\nPress \"Enter\" when complete. If you message contains characters that cannot be read on a command line, \nor \"Enter\" must be pressed for any reason other than continuing, it is recommended that you add a message file created through another editor.\n" ) file_not_found_menu(cwd) elif file_not_found_menu_choice == 4: controller.main_menu() elif file_not_found_menu_choice == 5: print("Goodbye...") sys.exit(0) else: print("\nInvalid Option...") file_not_found_menu(cwd)
def record_menu(cwd, ret): if ret == 1: print( "\nAttention: An Audio File Has Been Found. Continuing Will Overwrite This File." ) print("\n\tDo You Wish To Continue?\n\t1. Yes \n\t2. No") try: overwrite_choice = int(input("Please Select an Option: ")) except ValueError: print("\tError: Value Must Be A Number.\n") record_menu(cwd, ret) if overwrite_choice == 1: record(cwd, ret) controller.main_menu() elif overwrite_choice == 2: file_found_menu(cwd) else: print("Invalid Option: Must Be 1 or 2...") record_menu(cwd, ret)
def file_not_found_menu(cwd): ret = 0 print("\n-----FILE NOT FOUND MENU-----") print("\n\tOptions:") print("\t1. Add Audio File") print("\t2. Record Audio File (Not Implemented)") print("\t3. Help") print("\t4. Return To Main Menu") print("\t5. Exit") try: file_not_found_menu_choice = int(input("Please Select an Option: ")) except ValueError: print("\tError: Value Must Be A Number.\n") file_not_found_menu(cwd) if file_not_found_menu_choice == 1: input( "Halting... Please Add an Audio File to the Directory.\nPress \"Enter\" To Continue..." ) main() elif file_not_found_menu_choice == 2: record(cwd, ret) controller.main_menu() elif file_not_found_menu_choice == 3: print( "\nAn audio file must exist in the \'decode_audio\'. This folder will contain the file to be decoded. \nFrom here, you may:\n\nAdd An Audio File: The program will wait. At this point, you may add your own audio file to the directory. \nWhen you have done this, the program will prompt you to continue, and will rescan the directory for the audio file. \n\n-----NOTE: THIS PROGRAM ONLY SUPPORTS .WAV FILES.-----\n\nRecord An Audio File: The program will begin recording through your system's microphone. \nPress \"Enter\" when complete. \nYour Audio File will be stored as a .wav file. \nIf you have created an audio file through the encoder, you must manually add it to the \'decode_audio\' folder from the \'generated_audio\' folder.\n" ) file_not_found_menu(cwd) elif file_not_found_menu_choice == 4: controller.main_menu() elif file_not_found_menu_choice == 5: print("Goodbye...") sys.exit(0) else: print("\nInvalid Option...") file_not_found_menu(cwd)
import controller as controller if __name__ == "__main__": controller.main_menu()
def file_found_menu(cwd): ret = 1 print("\n-----FILE FOUND MENU-----") print("\n\tOptions:") print("\t1. Overwrite Message File") print("\t2. Delete Message File") print("\t3. View Message File") print("\t4. Help") print("\t5. Return To Main Menu") print("\t6. Exit") try: file_found_menu_choice = int(input("Please Select an Option: ")) except ValueError: print("\tError: Value Must Be A Number.\n") file_found_menu(cwd) if file_found_menu_choice == 1: if os.path.isfile(cwd + '/message.txt'): overwrite(cwd, ret) else: print( "Error: A Message File has been removed from the directory. \n\tResetting..." ) main() elif file_found_menu_choice == 2: print("\nAttention: This Option Will Delete Message Files.") print("\n\tDo You Wish To Continue?\n\t1. Yes \n\t2. No") try: delete_choice = int(input("Please Select an Option: ")) except ValueError: print("\tError: Value Must Be A Number.\n") file_found_menu(cwd) if delete_choice == 1: if os.path.exists("message.txt"): os.remove("message.txt") print("\nMessage File Deleted.\nReturning...") main() else: print("Message File Not Found\n\tExiting...") main() elif delete_choice == 2: print("Returning...") main() else: print("Invalid Option: Must Be 1 or 2...") file_found_menu(cwd) elif file_found_menu_choice == 3: print("\n-----MESSAGE FILE CONTENTS-----\n") with open("message.txt", 'r') as f: cat = f.read() print(cat) print("\n-----END MESSAGE FILE-----\n") file_found_menu(cwd) elif file_found_menu_choice == 4: print( "\nA message file must exist in the same directory as the program. This file contains the message to be encoded. \nFrom here, you may:\n\nOverwrite A Message File: Take an existing message file and overwrite its contents with a new message. \n\nDelete A Message File: Delete a existing message file.\n\n View Message File: Print out the coontents of the message file.\n" ) file_found_menu(cwd) elif file_found_menu_choice == 5: controller.main_menu() elif file_found_menu_choice == 6: print("Goodbye...") sys.exit(0) else: print("\nInvalid Option...") file_found_menu(cwd)
def main(): controller.main_menu()
def file_found_menu(cwd): ret = 1 print("\n-----FILE FOUND MENU-----") print("\n\tOptions:") print("\t1. Overwrite Audio File") print("\t2. Delete Audio File") print("\t3. Play Audio File") print("\t4. Help") print("\t5. Return To Main Menu") print("\t6. Exit") try: file_found_menu_choice = int(input("Please Select an Option: ")) except ValueError: print("\tError: Value Must Be A Number.\n") file_found_menu(cwd) if file_found_menu_choice == 1: if len(os.listdir(cwd)) > 0: record(cwd, ret) else: print( "Error: An Audio File has been removed from the directory. \n\tResetting..." ) main() elif file_found_menu_choice == 2: print("\nAttention: This Option Will Delete Your Audio File.") print("\n\tDo You Wish To Continue?\n\t1. Yes \n\t2. No") try: delete_choice = int(input("Please Select an Option: ")) except ValueError: print("\tError: Value Must Be A Number.\n") file_found_menu(cwd) if delete_choice == 1: for f in os.listdir(cwd): os.remove(os.path.join(cwd, f)) print("Audio File Deleted...") main() elif delete_choice == 2: print("Returning...") main() else: print("Invalid Option: Must Be 1 or 2...") file_found_menu(cwd) elif file_found_menu_choice == 3: for f in os.listdir(cwd): file_path = os.path.join(cwd, f) print("\n-----PLAYING AUDIO FILE-----\n") audio_file = AudioSegment.from_wav(file_path) play(audio_file) print("\n-----END AUDIO FILE-----\n") file_found_menu(cwd) elif file_found_menu_choice == 4: print( "\nAn audiofile must exist in the same directory as the program. This file contains the audio to be decoded. \nFrom here, you may:\n\nOverwrite An Audio File: Take an existing audio file and overwrite its contents with new audio. \n\nDelete An Audio File: Delete an existing audio file.\n\nPlay Audio File: Play the contents of an audio file.\n" ) file_found_menu(cwd) elif file_found_menu_choice == 5: controller.main_menu() elif file_found_menu_choice == 6: print("Goodbye...") sys.exit(0) else: print("\nInvalid Option...") file_found_menu(cwd)