
import random
import sys

from . import cryptomath_module as cryptomath

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

def a__   (	A_,					A_,					A_ ):






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

def a__   (	A_,					A_ ):






  '''simple docstring'''





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

def a__   (	A_,					A_ ):






  '''simple docstring'''





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

def a__   (	):






  '''simple docstring'''





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

def a__   (	):






  '''simple docstring'''





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

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


if __name__ == "__main__":
    import doctest

    doctest.testmod()
    # main()



def a__   (	A_ ):






  '''simple docstring'''





  __magic_name__    					=	str(A_ ).strip()
  if not bin_string:
    raise ValueError("""Empty string was passed to the function""" )
  __magic_name__    					=	bin_string[0] == """-"""
  if is_negative:
    __magic_name__    					=	bin_string[1:]
  if not all(char in """01""" for char in bin_string ):
    raise ValueError("""Non-binary value was passed to the function""" )
  __magic_name__    					=	0
  for char in bin_string:
    __magic_name__    					=	2 * decimal_number + int(A_ )
  return -decimal_number if is_negative else decimal_number


if __name__ == "__main__":
    from doctest import testmod

    testmod()

