


'''simple docstring'''



import random
import sys

from . import cryptomath_module as cryptomath

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




def 	_a	(						_lowercase					:	Optional[int]			,					_lowercase					:	Optional[Any]			,					_lowercase					:	Tuple  ):





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




def 	_a	(						_lowercase					:	str			,					_lowercase					:	Any  ):





     '''simple docstring'''






     __UpperCAmelCase	: str  							=			divmod(_lowercase			,					len(_lowercase  )  )
     check_keys(_lowercase			,					_lowercase			,					'''encrypt'''  )
     __UpperCAmelCase	: Dict  							=			''''''
     for symbol in message:
          if symbol in SYMBOLS:
               __UpperCAmelCase	: Union[str, Any]  							=			SYMBOLS.find(_lowercase  )
               cipher_text += SYMBOLS[(sym_index * key_a + key_b) % len(_lowercase  )]
          else:
               cipher_text += symbol
     return cipher_text




def 	_a	(						_lowercase					:	List[str]			,					_lowercase					:	List[Any]  ):





     '''simple docstring'''






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




def 	_a	(						):





     '''simple docstring'''






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




def 	_a	(						):





     '''simple docstring'''






     __UpperCAmelCase	: List[Any]  							=			input('''Enter message: '''  ).strip()
     __UpperCAmelCase	: Optional[int]  							=			int(input('''Enter key [2000 - 9000]: '''  ).strip()  )
     __UpperCAmelCase	: List[Any]  							=			input('''Encrypt/Decrypt [E/D]: '''  ).strip().lower()

     if mode.startswith('''e'''  ):
          __UpperCAmelCase	: Any  							=			'''encrypt'''
          __UpperCAmelCase	: Any  							=			encrypt_message(_lowercase			,					_lowercase  )
     elif mode.startswith('''d'''  ):
          __UpperCAmelCase	: Optional[Any]  							=			'''decrypt'''
          __UpperCAmelCase	: Union[str, Any]  							=			decrypt_message(_lowercase			,					_lowercase  )
     print(F'\n{mode.title()}ed text: \n{translated}'  )


if __name__ == "__main__":
      import doctest

      doctest.testmod()
      # main()





def  lowerCAmelCase  (	UpperCAmelCase       )  ->str:






					"""simple docstring"""






					return " ".join(sorted(set(sentence.split()       )       )       )


if __name__ == "__main__":
				import doctest

				doctest.testmod()



