






"""simple docstring"""





import random
import sys

from . import cryptomath_module as cryptomath

UpperCamelCase			=      (
    r""" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`"""
    r"""abcdefghijklmnopqrstuvwxyz{|}~"""
)






def     A(  snake_case_						,       snake_case_						,       snake_case_		):
       """simple docstring"""





       if mode == "encrypt":
              if key_a == 1:
                     sys.exit(
                         "The affine cipher becomes weak when key "
                         "A is set to 1. Choose different key"		)
              if key_b == 0:
                     sys.exit(
                         "The affine cipher becomes weak when key "
                         "B is set to 0. Choose different key"		)
       if key_a < 0 or key_b < 0 or key_b > len(snake_case_		) - 1:
              sys.exit(
                  "Key A must be greater than 0 and key B must "
                  F"""be between 0 and {len(snake_case_		) - 1}."""		)
       if cryptomath.gcd(snake_case_						,       len(snake_case_		)		) != 1:
              sys.exit(
                  F"""Key A {key_a} and the symbol set size {len(snake_case_		)} """
                  "are not relatively prime. Choose a different key."		)






def     A(  snake_case_						,       snake_case_		):
       """simple docstring"""





       lowercase__  ,     lowercase__:    List[str]        =      divmod(snake_case_						,       len(snake_case_		)		)
       check_keys(snake_case_						,       snake_case_						,       "encrypt"		)
       lowercase__:    Tuple        =      ""
       for symbol in message:
              if symbol in SYMBOLS:
                     lowercase__:    List[str]        =      SYMBOLS.find(snake_case_		)
                     cipher_text += SYMBOLS[(sym_index * key_a + key_b) % len(snake_case_		)]
              else:
                     cipher_text += symbol
       return cipher_text






def     A(  snake_case_						,       snake_case_		):
       """simple docstring"""





       lowercase__  ,     lowercase__:    List[Any]        =      divmod(snake_case_						,       len(snake_case_		)		)
       check_keys(snake_case_						,       snake_case_						,       "decrypt"		)
       lowercase__:    Optional[Any]        =      ""
       lowercase__:    int        =      cryptomath.find_mod_inverse(snake_case_						,       len(snake_case_		)		)
       for symbol in message:
              if symbol in SYMBOLS:
                     lowercase__:    List[Any]        =      SYMBOLS.find(snake_case_		)
                     plain_text += SYMBOLS[
                         (sym_index - key_b) * mod_inverse_of_key_a % len(snake_case_		)
                     ]
              else:
                     plain_text += symbol
       return plain_text






def     A(  ):
       """simple docstring"""





       while True:
              lowercase__:    str        =      random.randint(2						,       len(snake_case_		)		)
              lowercase__:    List[Any]        =      random.randint(2						,       len(snake_case_		)		)
              if cryptomath.gcd(snake_case_						,       len(snake_case_		)		) == 1 and key_b % len(snake_case_		) != 0:
                     return key_b * len(snake_case_		) + key_b






def     A(  ):
       """simple docstring"""





       lowercase__:    Tuple        =      input("Enter message: "		).strip()
       lowercase__:    Union[str, Any]        =      int(input("Enter key [2000 - 9000]: "		).strip()		)
       lowercase__:    Optional[int]        =      input("Encrypt/Decrypt [E/D]: "		).strip().lower()

       if mode.startswith("e"		):
              lowercase__:    Dict        =      "encrypt"
              lowercase__:    Optional[Any]        =      encrypt_message(snake_case_						,       snake_case_		)
       elif mode.startswith("d"		):
              lowercase__:    int        =      "decrypt"
              lowercase__:    Optional[int]        =      decrypt_message(snake_case_						,       snake_case_		)
       print(F"""\n{mode.title()}ed text: \n{translated}"""		)


if __name__ == "__main__":
  import doctest

  doctest.testmod()
  # main()














"""simple docstring"""





class 		_a       :





   '''simple docstring'''






   def __init__(   self			,				UpperCAmelCase_=None)	-> List[Any]:




          '''simple docstring'''




          lowercase__:    str        =      data
          lowercase__:    Any        =      None





   def __repr__(   self)	-> Optional[Any]:




          '''simple docstring'''




          lowercase__:    Any        =      ""
          lowercase__:    Dict        =      self
          while temp:
                 string_rep += F"""<{temp.data}> ---> """
                 lowercase__:    Tuple        =      temp.next
          string_rep += "<END>"
          return string_rep







def     A(  snake_case_		):
       """simple docstring"""





       if not elements_list:
              raise Exception("The Elements List is empty"		)

       # Set first element as Head
       lowercase__:    Any        =      Node(elements_list[0]		)
       lowercase__:    Optional[int]        =      head
       # Loop through elements from position 1
       for data in elements_list[1:]:
              lowercase__:    Dict        =      Node(snake_case_		)
              lowercase__:    Dict        =      current.next
       return head


UpperCamelCase			=      [1, 3, 5, 32, 44, 12, 43]
print(F"List: {list_data}")
print("""Creating Linked List from List.""")
UpperCamelCase			=      make_linked_list(list_data)
print("""Linked List:""")







print(linked_list)






