





import random
import sys

from . import cryptomath_module as cryptomath

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





def 							a__     (					_UpperCAmelCase		,       _UpperCAmelCase		,       _UpperCAmelCase		)      ->					None:

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





def 							a__     (					_UpperCAmelCase		,       _UpperCAmelCase		)      ->					str:

 '''simple docstring'''






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





def 							a__     (					_UpperCAmelCase		,       _UpperCAmelCase		)      ->					str:

 '''simple docstring'''






 snake_case__							,				snake_case__      							=			divmod(UpperCamelCase_		,       len(UpperCamelCase_		)		)
 check_keys(UpperCamelCase_		,       UpperCamelCase_		,       "decrypt"		)
 snake_case__      							=			""
 snake_case__      							=			cryptomath.find_mod_inverse(UpperCamelCase_		,       len(UpperCamelCase_		)		)
 for symbol in message:
  if symbol in SYMBOLS:
   snake_case__      							=			SYMBOLS.find(UpperCamelCase_		)
   plain_text += SYMBOLS[
       (sym_index - key_b) * mod_inverse_of_key_a % len(UpperCamelCase_		)
   ]
  else:
   plain_text += symbol
 return plain_text





def 							a__     (					)      ->					int:

 '''simple docstring'''






 while True:
  snake_case__      							=			random.randint(2		,       len(UpperCamelCase_		)		)
  snake_case__      							=			random.randint(2		,       len(UpperCamelCase_		)		)
  if cryptomath.gcd(UpperCamelCase_		,       len(UpperCamelCase_		)		) == 1 and key_b % len(UpperCamelCase_		) != 0:
   return key_b * len(UpperCamelCase_		) + key_b





def 							a__     (					)      ->					None:

 '''simple docstring'''






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

 if mode.startswith("e"		):
  snake_case__      							=			"encrypt"
  snake_case__      							=			encrypt_message(UpperCamelCase_		,       UpperCamelCase_		)
 elif mode.startswith("d"		):
  snake_case__      							=			"decrypt"
  snake_case__      							=			decrypt_message(UpperCamelCase_		,       UpperCamelCase_		)
 print(f"\n{mode.title()}ed text: \n{translated}"		)


if __name__ == "__main__":
   import doctest

   doctest.testmod()
   # main()








"""simple docstring"""


import math





def 							a__     (					_UpperCAmelCase		)      ->					list:

 '''simple docstring'''






 if n <= 0:
  raise ValueError("Only positive integers have prime factors"		)
 snake_case__      							=			[]
 while n % 2 == 0:
  pf.append(2		)
  snake_case__      							=			int(n / 2		)
 for i in range(3		,       int(math.sqrt(_UpperCAmelCase		)		) + 1		,       2		):
  while n % i == 0:
   pf.append(_UpperCAmelCase		)
   snake_case__      							=			int(n / i		)
 if n > 2:
  pf.append(_UpperCAmelCase		)
 return pf





def 							a__     (					_UpperCAmelCase		)      ->					int:

 '''simple docstring'''






 if n <= 0:
  raise ValueError("Only positive numbers are accepted"		)
 snake_case__      							=			1
 snake_case__      							=			1
 while n % 2 == 0:
  temp += 1
  snake_case__      							=			int(n / 2		)
 div *= temp
 for i in range(3		,       int(math.sqrt(_UpperCAmelCase		)		) + 1		,       2		):
  snake_case__      							=			1
  while n % i == 0:
   temp += 1
   snake_case__      							=			int(n / i		)
  div *= temp
 if n > 1:
  div *= 2
 return div





def 							a__     (					_UpperCAmelCase		)      ->					int:

 '''simple docstring'''






 if n <= 0:
  raise ValueError("Only positive numbers are accepted"		)
 snake_case__      							=			1
 snake_case__      							=			1
 while n % 2 == 0:
  temp += 1
  snake_case__      							=			int(n / 2		)
 if temp > 1:
  s *= (2**temp - 1) / (2 - 1)
 for i in range(3		,       int(math.sqrt(_UpperCAmelCase		)		) + 1		,       2		):
  snake_case__      							=			1
  while n % i == 0:
   temp += 1
   snake_case__      							=			int(n / i		)
  if temp > 1:
   s *= (i**temp - 1) / (i - 1)
 return int(_UpperCAmelCase		)





def 							a__     (					_UpperCAmelCase		)      ->					int:

 '''simple docstring'''






 snake_case__      							=			n
 for x in set(prime_factors(_UpperCAmelCase		)		):
  s *= (x - 1) / x
 return int(_UpperCAmelCase		)


if __name__ == "__main__":
   import doctest

   doctest.testmod()

