



import random
import sys

UpperCAmelCase				:							str								="""ABCDEFGHIJKLMNOPQRSTUVWXYZ"""



def 				_lowerCAmelCase      ():
					UpperCamelCase_											=				input("Enter message: ")
					UpperCamelCase_											=				"LFWOAYUISVKMNXPBDCRJTQEGHZ"
					UpperCamelCase_											=				input("Encrypt/Decrypt [e/d]: ")

					check_valid_key(_lowerCAmelCase)

					if resp.lower().startswith("e"):
										UpperCamelCase_											=				"encrypt"
										UpperCamelCase_											=				encrypt_message(_lowerCAmelCase				,		_lowerCAmelCase)
					elif resp.lower().startswith("d"):
										UpperCamelCase_											=				"decrypt"
										UpperCamelCase_											=				decrypt_message(_lowerCAmelCase				,		_lowerCAmelCase)

					print(f"""\n{mode.title()}ion: \n{translated}""")



def 				_lowerCAmelCase      (_lowerCAmelCase):
					UpperCamelCase_											=				list(_lowerCAmelCase)
					UpperCamelCase_											=				list(_lowerCAmelCase)
					key_list.sort()
					letters_list.sort()

					if key_list != letters_list:
										sys.exit("Error in the key or symbol set.")



def 				_lowerCAmelCase      (_lowerCAmelCase				,		_lowerCAmelCase):
					return translate_message(_lowerCAmelCase				,		_lowerCAmelCase				,		"encrypt")



def 				_lowerCAmelCase      (_lowerCAmelCase				,		_lowerCAmelCase):
					return translate_message(_lowerCAmelCase				,		_lowerCAmelCase				,		"decrypt")



def 				_lowerCAmelCase      (_lowerCAmelCase				,		_lowerCAmelCase				,		_lowerCAmelCase):
					UpperCamelCase_											=				""
					UpperCamelCase_											=				LETTERS
					UpperCamelCase_											=				key

					if mode == "decrypt":
										UpperCamelCase_					,      UpperCamelCase_											=				chars_b, chars_a

					for symbol in message:
										if symbol.upper() in chars_a:
															UpperCamelCase_											=				chars_a.find(symbol.upper())
															if symbol.isupper():
																				translated += chars_b[sym_index].upper()
															else:
																				translated += chars_b[sym_index].lower()
										else:
															translated += symbol

					return translated



def 				_lowerCAmelCase      ():
					UpperCamelCase_											=				list(_lowerCAmelCase)
					random.shuffle(_lowerCAmelCase)
					return "".join(_lowerCAmelCase)


if __name__ == "__main__":
	main()





from typing import Literal

UpperCAmelCase				:							Tuple								="""ABCDEFGHIJKLMNOPQRSTUVWXYZ"""



def 				_lowerCAmelCase      (_lowerCAmelCase				,		_lowerCAmelCase				,		_lowerCAmelCase):
					UpperCamelCase_											=				LETTERS if mode == "decrypt" else key
					UpperCamelCase_											=				key if mode == "decrypt" else LETTERS
					UpperCamelCase_											=				""
					# loop through each symbol in the message
					for symbol in message:
										if symbol.upper() in chars_a:
															# encrypt/decrypt the symbol
															UpperCamelCase_											=				chars_a.find(symbol.upper())
															if symbol.isupper():
																				translated += chars_b[sym_index].upper()
															else:
																				translated += chars_b[sym_index].lower()
										else:
															# symbol is not in LETTERS, just add it
															translated += symbol
					return translated



def 				_lowerCAmelCase      (_lowerCAmelCase				,		_lowerCAmelCase):
					return translate_message(_lowerCAmelCase				,		_lowerCAmelCase				,		"encrypt")



def 				_lowerCAmelCase      (_lowerCAmelCase				,		_lowerCAmelCase):
					return translate_message(_lowerCAmelCase				,		_lowerCAmelCase				,		"decrypt")



def 				_lowerCAmelCase      ():
					UpperCamelCase_											=				"Hello World"
					UpperCamelCase_											=				"QWERTYUIOPASDFGHJKLZXCVBNM"
					UpperCamelCase_											=				"decrypt"  # set to 'encrypt' or 'decrypt'

					if mode == "encrypt":
										UpperCamelCase_											=				encrypt_message(_lowerCAmelCase				,		_lowerCAmelCase)
					elif mode == "decrypt":
										UpperCamelCase_											=				decrypt_message(_lowerCAmelCase				,		_lowerCAmelCase)
					print(f"""Using the key {key}, the {mode}ed message is: {translated}""")


if __name__ == "__main__":
	import doctest

	doctest.testmod()
	main()
