





"""simple docstring"""






import random
import sys

from . import cryptomath_module as cryptomath

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

def    __lowerCamelCase     (							SCREAMING_SNAKE_CASE,SCREAMING_SNAKE_CASE,SCREAMING_SNAKE_CASE				)		->							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(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    __lowerCamelCase     (							SCREAMING_SNAKE_CASE,SCREAMING_SNAKE_CASE				)		->							str:






       """simple docstring"""




       _UpperCAmelCase     ,				_UpperCAmelCase			     =  divmod(SCREAMING_SNAKE_CASE,len(SCREAMING_SNAKE_CASE				)				)
       check_keys(SCREAMING_SNAKE_CASE,SCREAMING_SNAKE_CASE,'encrypt'				)
       _UpperCAmelCase			     =  ''
       for symbol in message:
              if symbol in SYMBOLS:
                     _UpperCAmelCase			     =  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    __lowerCamelCase     (							SCREAMING_SNAKE_CASE,SCREAMING_SNAKE_CASE				)		->							str:






       """simple docstring"""




       _UpperCAmelCase     ,				_UpperCAmelCase			     =  divmod(SCREAMING_SNAKE_CASE,len(SCREAMING_SNAKE_CASE				)				)
       check_keys(SCREAMING_SNAKE_CASE,SCREAMING_SNAKE_CASE,'decrypt'				)
       _UpperCAmelCase			     =  ''
       _UpperCAmelCase			     =  cryptomath.find_mod_inverse(SCREAMING_SNAKE_CASE,len(SCREAMING_SNAKE_CASE				)				)
       for symbol in message:
              if symbol in SYMBOLS:
                     _UpperCAmelCase			     =  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    __lowerCamelCase     (							)		->							int:






       """simple docstring"""




       while True:
              _UpperCAmelCase			     =  random.randint(2,len(SCREAMING_SNAKE_CASE				)				)
              _UpperCAmelCase			     =  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    __lowerCamelCase     (							)		->							None:






       """simple docstring"""




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

       if mode.startswith('e'				):
              _UpperCAmelCase			     =  'encrypt'
              _UpperCAmelCase			     =  encrypt_message(SCREAMING_SNAKE_CASE,SCREAMING_SNAKE_CASE				)
       elif mode.startswith('d'				):
              _UpperCAmelCase			     =  'decrypt'
              _UpperCAmelCase			     =  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    __lowerCamelCase     (							SCREAMING_SNAKE_CASE				)		->							bool:






       """simple docstring"""




       if not isinstance(SCREAMING_SNAKE_CASE,SCREAMING_SNAKE_CASE				):
              raise ValueError('Input series is not valid, valid series - [2, 4, 8]'				)
       if len(SCREAMING_SNAKE_CASE				) == 0:
              raise ValueError('Input list must be a non empty list'				)
       if len(SCREAMING_SNAKE_CASE				) == 1:
              return True
       try:
              _UpperCAmelCase			     =  series[1] / series[0]
              for index in range(len(SCREAMING_SNAKE_CASE				) - 1				):
                     if series[index + 1] / series[index] != common_ratio:
                            return False
       except ZeroDivisionError:
              return False
       return True

def    __lowerCamelCase     (							SCREAMING_SNAKE_CASE				)		->							float:






       """simple docstring"""




       if not isinstance(SCREAMING_SNAKE_CASE,SCREAMING_SNAKE_CASE				):
              raise ValueError('Input series is not valid, valid series - [2, 4, 8]'				)
       if len(SCREAMING_SNAKE_CASE				) == 0:
              raise ValueError('Input list must be a non empty list'				)
       _UpperCAmelCase			     =  1
       for value in series:
              answer *= value
       return pow(SCREAMING_SNAKE_CASE,1 / len(SCREAMING_SNAKE_CASE				)				)


if __name__ == "__main__":
    import doctest

    doctest.testmod()






