
'''simple docstring'''
import random
import sys

from . import cryptomath_module as cryptomath

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

def     UpperCamelCase_  (						__SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE							):
    """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     UpperCamelCase_  (						__SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE							):
    """simple docstring"""






    snake_case_      ,			snake_case_			:     int        =    divmod(__SCREAMING_SNAKE_CASE,		len(__SCREAMING_SNAKE_CASE							)							)
    check_keys(__SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE,		"encrypt"							)
    snake_case_			:     List[str]        =    ""
    for symbol in message:
        if symbol in SYMBOLS:
            snake_case_			:     Any        =    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     UpperCamelCase_  (						__SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE							):
    """simple docstring"""






    snake_case_      ,			snake_case_			:     List[Any]        =    divmod(__SCREAMING_SNAKE_CASE,		len(__SCREAMING_SNAKE_CASE							)							)
    check_keys(__SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE,		"decrypt"							)
    snake_case_			:     Union[str, Any]        =    ""
    snake_case_			:     Optional[int]        =    cryptomath.find_mod_inverse(__SCREAMING_SNAKE_CASE,		len(__SCREAMING_SNAKE_CASE							)							)
    for symbol in message:
        if symbol in SYMBOLS:
            snake_case_			:     str        =    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     UpperCamelCase_  (						):
    """simple docstring"""






    while True:
        snake_case_			:     List[str]        =    random.randint(2,		len(__SCREAMING_SNAKE_CASE							)							)
        snake_case_			:     Dict        =    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     UpperCamelCase_  (						):
    """simple docstring"""






    snake_case_			:     Tuple        =    input("Enter message: "							).strip()
    snake_case_			:     Union[str, Any]        =    int(input("Enter key [2000 - 9000]: "							).strip()							)
    snake_case_			:     List[Any]        =    input("Encrypt/Decrypt [E/D]: "							).strip().lower()

    if mode.startswith("e"							):
        snake_case_			:     Optional[int]        =    "encrypt"
        snake_case_			:     Optional[Any]        =    encrypt_message(__SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE							)
    elif mode.startswith("d"							):
        snake_case_			:     Optional[int]        =    "decrypt"
        snake_case_			:     Optional[Any]        =    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'''
import itertools

def     UpperCamelCase_  (						__SCREAMING_SNAKE_CASE = 1_0_0_0_0_0_0							):
    """simple docstring"""






    snake_case_			:     Optional[int]        =    [1]

    for i in itertools.count(len(__SCREAMING_SNAKE_CASE							)							):
        snake_case_			:     str        =    0
        for j in itertools.count(1							):
            snake_case_			:     List[str]        =    -1 if j % 2 == 0 else +1
            snake_case_			:     str        =    (j * j * 3 - j) // 2
            if index > i:
                break
            item += partitions[i - index] * sign
            item %= number
            index += j
            if index > i:
                break
            item += partitions[i - index] * sign
            item %= number

        if item == 0:
            return i
        partitions.append(__SCREAMING_SNAKE_CASE							)

    return 0


if __name__ == "__main__":
  import doctest

  doctest.testmod()

  print(f"""{solution() = }""")




