






'''simple docstring'''





import random
import sys

from . import cryptomath_module as cryptomath

_UpperCamelCase		:		Optional[Any]								=			(
    R' !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`'
    R'abcdefghijklmnopqrstuvwxyz{|}~'
)
def __UpperCAmelCase (			A			:	Tuple	,   A			:	Union[str, Any]	,   A			:	Tuple						)  -> Optional[Any]:
			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 __UpperCAmelCase (			A			:	Optional[Any]	,   A			:	str						)  -> List[Any]:
			UpperCAmelCase_     :   Union[str, Any]       =   divmod(snake_case__	,   len(snake_case__						)						)
			check_keys(snake_case__	,   snake_case__	,   '''encrypt'''						)
			UpperCAmelCase_     :   Dict       =   ""
			for symbol in message:
						if symbol in SYMBOLS:
									UpperCAmelCase_     :   Tuple       =   SYMBOLS.find(snake_case__						)
									cipher_text += SYMBOLS[(sym_index * key_a + key_b) % len(snake_case__						)]
						else:
									cipher_text += symbol
			return cipher_text
def __UpperCAmelCase (			A			:	str	,   A			:	Tuple						)  -> Dict:
			UpperCAmelCase_     :   Union[str, Any]       =   divmod(snake_case__	,   len(snake_case__						)						)
			check_keys(snake_case__	,   snake_case__	,   '''decrypt'''						)
			UpperCAmelCase_     :   List[str]       =   ""
			UpperCAmelCase_     :   Tuple       =   cryptomath.find_mod_inverse(snake_case__	,   len(snake_case__						)						)
			for symbol in message:
						if symbol in SYMBOLS:
									UpperCAmelCase_     :   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 __UpperCAmelCase (			)  -> Optional[int]:
			while True:
						UpperCAmelCase_     :   str       =   random.randint(2	,   len(snake_case__						)						)
						UpperCAmelCase_     :   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 __UpperCAmelCase (			)  -> Tuple:
			UpperCAmelCase_     :   List[str]       =   input('''Enter message: '''						).strip()
			UpperCAmelCase_     :   Union[str, Any]       =   int(input('''Enter key [2000 - 9000]: '''						).strip()						)
			UpperCAmelCase_     :   Tuple       =   input('''Encrypt/Decrypt [E/D]: '''						).strip().lower()

			if mode.startswith('''e'''						):
						UpperCAmelCase_     :   str       =   "encrypt"
						UpperCAmelCase_     :   Tuple       =   encrypt_message(snake_case__	,   snake_case__						)
			elif mode.startswith('''d'''						):
						UpperCAmelCase_     :   str       =   "decrypt"
						UpperCAmelCase_     :   Dict       =   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'''





def __UpperCAmelCase (			)  -> Optional[Any]:
			UpperCAmelCase_     :   Union[str, Any]       =   1

			while True:
						if (
						    sorted(str(A						)						)
						    == sorted(str(2 * i						)						)
						    == sorted(str(3 * i						)						)
						    == sorted(str(4 * i						)						)
						    == sorted(str(5 * i						)						)
						    == sorted(str(6 * i						)						)
						):
									return i

						i += 1


if __name__ == "__main__":
						print(solution())


