





from __future__ import annotations

from string import ascii_letters



def   lowerCAmelCase						(						_lowerCAmelCase							:				Optional[int]  ,							_lowerCAmelCase							:				Any  ,							_lowerCAmelCase							:				List[str] = None		):




 """simple docstring"""







 UpperCAmelCase__								=  alphabet or ascii_letters

 # The final result string
 UpperCAmelCase__								=  ''''''

 for character in input_string:
  if character not in alpha:
   # Append without encryption if character is not in the alphabet
   result += character
  else:
   # Get the index of the new key and make sure it isn't too large
   UpperCAmelCase__								=  (alpha.index(_lowerCAmelCase		) + key) % len(_lowerCAmelCase		)

   # Append the encoded character to the alphabet
   result += alpha[new_key]

 return result



def   lowerCAmelCase						(						_lowerCAmelCase							:				int  ,							_lowerCAmelCase							:				int  ,							_lowerCAmelCase							:				Optional[int] = None		):




 """simple docstring"""







 key *= -1

 return encrypt(_lowerCAmelCase  ,							_lowerCAmelCase  ,							_lowerCAmelCase		)



def   lowerCAmelCase						(						_lowerCAmelCase							:				Optional[int]  ,							_lowerCAmelCase							:				Union[str, Any] = None		):




 """simple docstring"""







 UpperCAmelCase__								=  alphabet or ascii_letters

 # To store data on all the combinations
 UpperCAmelCase__								=  {}

 # Cycle through each combination
 for key in range(1  ,							len(_lowerCAmelCase		) + 1		):
  # Decrypt the message and store the result in the data
  UpperCAmelCase__								=  decrypt(_lowerCAmelCase  ,							_lowerCAmelCase  ,							_lowerCAmelCase		)

 return brute_force_data


if __name__ == "__main__":
  while True:
    print(F'''\n{"-" * 1_0}\n Menu\n{"-" * 1_0}''')
    print(*["1.Encrypt", "2.Decrypt", "3.BruteForce", "4.Quit"], sep="\n")

    # get user input
    _lowerCAmelCase  :				Optional[Any]						=				input("\nWhat would you like to do?: ").strip() or "4"

    # run functions based on what the user chose
    if choice not in ("1", "2", "3", "4"):
      print("Invalid choice, please enter a valid choice")
    elif choice == "1":
      _lowerCAmelCase  :				str						=				input("Please enter the string to be encrypted: ")
      _lowerCAmelCase  :				str						=				int(input("Please enter off-set: ").strip())

      print(encrypt(input_string, key))
    elif choice == "2":
      _lowerCAmelCase  :				Optional[Any]						=				input("Please enter the string to be decrypted: ")
      _lowerCAmelCase  :				int						=				int(input("Please enter off-set: ").strip())

      print(decrypt(input_string, key))
    elif choice == "3":
      _lowerCAmelCase  :				int						=				input("Please enter the string to be decrypted: ")
      _lowerCAmelCase  :				Union[str, Any]						=				brute_force(input_string)

      for key, value in brute_force_data.items():
        print(F'''Key: {key} | Message: {value}''')

    elif choice == "4":
      print("Goodbye.")
      break











from __future__ import annotations



def   lowerCAmelCase						(						_lowerCAmelCase							:				int  ,							_lowerCAmelCase							:				int  ,							_lowerCAmelCase							:				int		):




 """simple docstring"""







 assert (
     c % greatest_common_divisor(_lowerCAmelCase  ,							_lowerCAmelCase		) == 0
 )  # greatest_common_divisor(a,b) function implemented below
 ((UpperCAmelCase__)	,	(UpperCAmelCase__)	,	(UpperCAmelCase__))								=  extended_gcd(_lowerCAmelCase  ,							_lowerCAmelCase		)  # extended_gcd(a,b) function implemented below
 UpperCAmelCase__								=  c / d
 return (r * x, r * y)



def   lowerCAmelCase						(						_lowerCAmelCase							:				int  ,							_lowerCAmelCase							:				int  ,							_lowerCAmelCase							:				int  ,							_lowerCAmelCase							:				int = 2		):




 """simple docstring"""







 ((UpperCAmelCase__)	,	(UpperCAmelCase__))								=  diophantine(_lowerCAmelCase  ,							_lowerCAmelCase  ,							_lowerCAmelCase		)  # Initial value
 UpperCAmelCase__								=  greatest_common_divisor(_lowerCAmelCase  ,							_lowerCAmelCase		)
 UpperCAmelCase__								=  a // d
 UpperCAmelCase__								=  b // d

 for i in range(_lowerCAmelCase		):
  UpperCAmelCase__								=  xa + i * q
  UpperCAmelCase__								=  ya - i * p
  print(_lowerCAmelCase  ,							_lowerCAmelCase		)



def   lowerCAmelCase						(						_lowerCAmelCase							:				int  ,							_lowerCAmelCase							:				int		):




 """simple docstring"""







 if a < b:
  UpperCAmelCase__	,	UpperCAmelCase__								=  b, a

 while a % b != 0:
  UpperCAmelCase__	,	UpperCAmelCase__								=  b, a % b

 return b



def   lowerCAmelCase						(						_lowerCAmelCase							:				int  ,							_lowerCAmelCase							:				int		):




 """simple docstring"""







 assert a >= 0 and b >= 0

 if b == 0:
  UpperCAmelCase__	,	UpperCAmelCase__	,	UpperCAmelCase__								=  a, 1, 0
 else:
  ((UpperCAmelCase__)	,	(UpperCAmelCase__)	,	(UpperCAmelCase__))								=  extended_gcd(_lowerCAmelCase  ,							a % b		)
  UpperCAmelCase__								=  q
  UpperCAmelCase__								=  p - q * (a // b)

 assert a % d == 0 and b % d == 0
 assert d == a * x + b * y

 return (d, x, y)


if __name__ == "__main__":
  from doctest import testmod

  testmod(name="diophantine", verbose=True)
  testmod(name="diophantine_all_soln", verbose=True)
  testmod(name="extended_gcd", verbose=True)
  testmod(name="greatest_common_divisor", verbose=True)





