


'''simple docstring'''


import random
import sys

from . import cryptomath_module as cryptomath

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







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







def       snake_case_       (  SCREAMING_SNAKE_CASE__							,				SCREAMING_SNAKE_CASE__					):







				"""simple docstring"""





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







def       snake_case_       (  SCREAMING_SNAKE_CASE__							,				SCREAMING_SNAKE_CASE__					):







				"""simple docstring"""





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







def       snake_case_       (  ):







				"""simple docstring"""





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







def       snake_case_       (  ):







				"""simple docstring"""





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

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


if __name__ == "__main__":
				import doctest

				doctest.testmod()
				# main()








'''simple docstring'''


def       snake_case_       (  SCREAMING_SNAKE_CASE__							,				SCREAMING_SNAKE_CASE__					):







				"""simple docstring"""





				_SCREAMING_SNAKE_CASE			:	Tuple							=				1
				while b > 0:
								if b & 1:
												res *= a

								a *= a
								b >>= 1

				return res







def       snake_case_       (  SCREAMING_SNAKE_CASE__							,				SCREAMING_SNAKE_CASE__							,				SCREAMING_SNAKE_CASE__					):







				"""simple docstring"""





				_SCREAMING_SNAKE_CASE			:	Union[str, Any]							=				1
				while b > 0:
								if b & 1:
												_SCREAMING_SNAKE_CASE			:	Tuple							=				((res % c) * (a % c)) % c

								a *= a
								b >>= 1

				return res




