





"""simple docstring"""
import random
import sys

from . import cryptomath_module as cryptomath

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



def   __lowerCamelCase     (							a_  :	int				,     a_  :	int				,     a_  :	str							)    ->   None:
      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(a_							) - 1:
            sys.exit(
                '''Key A must be greater than 0 and key B must '''
                f'''be between 0 and {len(a_							) - 1}.'''							)
      if cryptomath.gcd(a_				,     len(a_							)							) != 1:
            sys.exit(
                f'''Key A {key_a} and the symbol set size {len(a_							)} '''
                '''are not relatively prime. Choose a different key.'''							)



def   __lowerCamelCase     (							a_  :	int				,     a_  :	str							)    ->   str:
      __SCREAMING_SNAKE_CASE       ,__SCREAMING_SNAKE_CASE     :Any	       =						divmod(a_				,     len(a_							)							)
      check_keys(a_				,     a_				,     '''encrypt'''							)
      __SCREAMING_SNAKE_CASE     :Union[str, Any]	       =						''''''
      for symbol in message:
            if symbol in SYMBOLS:
                  __SCREAMING_SNAKE_CASE     :str	       =						SYMBOLS.find(a_							)
                  cipher_text += SYMBOLS[(sym_index * key_a + key_b) % len(a_							)]
            else:
                  cipher_text += symbol
      return cipher_text



def   __lowerCamelCase     (							a_  :	int				,     a_  :	str							)    ->   str:
      __SCREAMING_SNAKE_CASE       ,__SCREAMING_SNAKE_CASE     :int	       =						divmod(a_				,     len(a_							)							)
      check_keys(a_				,     a_				,     '''decrypt'''							)
      __SCREAMING_SNAKE_CASE     :Optional[Any]	       =						''''''
      __SCREAMING_SNAKE_CASE     :Tuple	       =						cryptomath.find_mod_inverse(a_				,     len(a_							)							)
      for symbol in message:
            if symbol in SYMBOLS:
                  __SCREAMING_SNAKE_CASE     :str	       =						SYMBOLS.find(a_							)
                  plain_text += SYMBOLS[
                      (sym_index - key_b) * mod_inverse_of_key_a % len(a_							)
                  ]
            else:
                  plain_text += symbol
      return plain_text



def   __lowerCamelCase     (							)    ->   int:
      while True:
            __SCREAMING_SNAKE_CASE     :str	       =						random.randint(2				,     len(a_							)							)
            __SCREAMING_SNAKE_CASE     :Dict	       =						random.randint(2				,     len(a_							)							)
            if cryptomath.gcd(a_				,     len(a_							)							) == 1 and key_b % len(a_							) != 0:
                  return key_b * len(a_							) + key_b



def   __lowerCamelCase     (							)    ->   None:
      __SCREAMING_SNAKE_CASE     :str	       =						input('''Enter message: '''							).strip()
      __SCREAMING_SNAKE_CASE     :Dict	       =						int(input('''Enter key [2000 - 9000]: '''							).strip()							)
      __SCREAMING_SNAKE_CASE     :Tuple	       =						input('''Encrypt/Decrypt [E/D]: '''							).strip().lower()

      if mode.startswith('''e'''							):
            __SCREAMING_SNAKE_CASE     :Dict	       =						'''encrypt'''
            __SCREAMING_SNAKE_CASE     :List[str]	       =						encrypt_message(a_				,     a_							)
      elif mode.startswith('''d'''							):
            __SCREAMING_SNAKE_CASE     :List[str]	       =						'''decrypt'''
            __SCREAMING_SNAKE_CASE     :Union[str, Any]	       =						decrypt_message(a_				,     a_							)
      print(f'''\n{mode.title()}ed text: \n{translated}'''							)


if __name__ == "__main__":
  import doctest

  doctest.testmod()
  # main()






"""simple docstring"""
def   __lowerCamelCase     (							a_  :	str							)    ->   int:
      __SCREAMING_SNAKE_CASE     :List[Any]	       =						0
      for plain_chr in plain_text:
            __SCREAMING_SNAKE_CASE     :List[str]	       =						(
                ord(a_							) + (hash_value << 6) + (hash_value << 16) - hash_value
            )
      return hash_value