




'''simple docstring'''






import random
import sys

from . import cryptomath_module as cryptomath

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

def       __lowerCAmelCase (   snake_case__ ,				snake_case__ ,				snake_case__						):
			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       __lowerCAmelCase (   snake_case__ ,				snake_case__						):
			__UpperCamelCase		, __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       __lowerCAmelCase (   snake_case__ ,				snake_case__						):
			__UpperCamelCase		, __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       __lowerCAmelCase (   ):
			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       __lowerCAmelCase (   ):
			__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'''






from doctest import testmod
from math import sqrt

def       __lowerCAmelCase (   snake_case__						):
			__UpperCamelCase				:      list[int]									=       []
			if num < 1:
						return facs
			facs.append(1						)
			if num == 1:
						return facs
			facs.append(snake_case__						)
			for i in range(2 ,				int(sqrt(snake_case__						)						) + 1						):
						if num % i == 0:  # If i is a factor of num
									facs.append(snake_case__						)
									__UpperCamelCase				:      List[str]									=       num // i  # num//i is the other factor of num
									if d != i:  # If d and i are distinct
												facs.append(snake_case__						)  # we have found another factor
			facs.sort()
			return facs


if __name__ == "__main__":
				testmod(name='''factors_of_a_number''', verbose=True)



