lowerCAmelCase__      		=					{
    '0000': '0',
    '0001': '1',
    '0010': '2',
    '0011': '3',
    '0100': '4',
    '0101': '5',
    '0110': '6',
    '0111': '7',
    '1000': '8',
    '1001': '9',
    '1010': 'a',
    '1011': 'b',
    '1100': 'c',
    '1101': 'd',
    '1110': 'e',
    '1111': 'f',
}






def  __lowerCamelCase						(		lowerCAmelCase__      ):
       lowerCAmelCase__	      =   str(lowerCAmelCase__      ).strip()

       # Exceptions
       if not binary_str:
              raise ValueError('Empty string was passed to the function'      )
       lowerCAmelCase__	      =   binary_str[0] == '-'
       lowerCAmelCase__	      =   binary_str[1:] if is_negative else binary_str
       if not all(char in '01' for char in binary_str      ):
              raise ValueError('Non-binary value was passed to the function'      )

       lowerCAmelCase__	      =   (
           '0' * (4 * (divmod(len(lowerCAmelCase__      )      ,    4      )[0] + 1) - len(lowerCAmelCase__      )) + binary_str
       )

       lowerCAmelCase__	      =   []
       for x in range(0      ,    len(lowerCAmelCase__      )      ,    4      ):
              hexadecimal.append(BITS_TO_HEX[binary_str[x : x + 4]]      )
       lowerCAmelCase__	      =   '0x' + ''.join(lowerCAmelCase__      )

       return "-" + hexadecimal_str if is_negative else hexadecimal_str


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

    testmod()

import random
import sys

from . import cryptomath_module as cryptomath

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






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






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






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






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






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

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


if __name__ == "__main__":
    import doctest

    doctest.testmod()
    # main()
