






import random
import sys

from . import cryptomath_module as cryptomath

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






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






def     A(  snake_case_						,       snake_case_		):
       """simple docstring"""





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






def     A(  snake_case_						,       snake_case_		):
       """simple docstring"""





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






def     A(  ):
       """simple docstring"""





       while True:
              lowercase__:    str        =      random.randint(2						,       len(snake_case_		)		)
              lowercase__:    List[Any]        =      random.randint(2						,       len(snake_case_		)		)
              if cryptomath.gcd(snake_case_						,       len(snake_case_		)		) == 1 and key_b % len(snake_case_		) != 0:
                     return key_b * len(snake_case_		) + key_b






def     A(  ):
       """simple docstring"""





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

       if mode.startswith("e"		):
              lowercase__:    Dict        =      "encrypt"
              lowercase__:    Optional[Any]        =      encrypt_message(snake_case_						,       snake_case_		)
       elif mode.startswith("d"		):
              lowercase__:    int        =      "decrypt"
              lowercase__:    Optional[int]        =      decrypt_message(snake_case_						,       snake_case_		)
       print(F"""\n{mode.title()}ed text: \n{translated}"""		)


if __name__ == "__main__":
  import doctest

  doctest.testmod()
  # main()














"""simple docstring"""





import warnings
from collections.abc import Callable
from typing import Any

import numpy
from matplotlib import pyplot

UpperCamelCase			=      0.25 + 0.0j
UpperCamelCase			=      -0.4 + 0.6j
UpperCamelCase			=      -0.1 + 0.651j
UpperCamelCase			=      -2.0
UpperCamelCase			=      56
UpperCamelCase			=      2.0
UpperCamelCase			=      6_66






def     A(  snake_case_						,       snake_case_		):
       """simple docstring"""





       return numpy.exp(snake_case_		) + c_parameter






def     A(  snake_case_						,       snake_case_		):
       """simple docstring"""





       return z_values * z_values + c_parameter






def     A(  snake_case_						,       snake_case_		):
       """simple docstring"""





       lowercase__:    str        =      numpy.linspace(-window_size						,       snake_case_						,       snake_case_		)
       lowercase__:    Union[str, Any]        =      x.reshape((nb_pixels, 1)		)
       lowercase__:    Any        =      numpy.linspace(-window_size						,       snake_case_						,       snake_case_		)
       lowercase__:    List[Any]        =      y.reshape((1, nb_pixels)		)
       return x + 1.0J * y






def     A(  snake_case_						,       snake_case_						,       snake_case_						,       snake_case_						,       snake_case_ = None						,       ):
       """simple docstring"""





       lowercase__:    List[Any]        =      z_a.astype("complex64"		)
       for _ in range(snake_case_		):
              lowercase__:    Any        =      eval_function(snake_case_						,       snake_case_		)
              if infinity is not None:
                     numpy.nan_to_num(snake_case_						,       copy=snake_case_						,       nan=snake_case_		)
                     lowercase__:    Union[str, Any]        =      infinity
       return z_n






def     A(  snake_case_						,       snake_case_						,       snake_case_						,       snake_case_						,       ):
       """simple docstring"""





       lowercase__:    Union[str, Any]        =      (abs(snake_case_		)).transpose()
       lowercase__:    List[Any]        =      abs_z_final[::-1, :]
       pyplot.matshow(abs_z_final < escape_radius		)
       pyplot.title(F"""Julia set of ${function_label}$, $c={function_params}$"""		)
       pyplot.show()






def     A(  ):
       """simple docstring"""





       warnings.filterwarnings(
           "ignore"						,       category=snake_case_						,       message="overflow encountered in multiply"		)
       warnings.filterwarnings(
           "ignore"						,       category=snake_case_						,       message="invalid value encountered in multiply"						,       )
       warnings.filterwarnings(
           "ignore"						,       category=snake_case_						,       message="overflow encountered in absolute"		)
       warnings.filterwarnings(
           "ignore"						,       category=snake_case_						,       message="overflow encountered in exp"		)


if __name__ == "__main__":
  UpperCamelCase			=      prepare_grid(window_size, nb_pixels)

  ignore_overflow_warnings()  # See file header for explanations

  UpperCamelCase			=      24
  UpperCamelCase			=      2 * abs(c_cauliflower) + 1
  UpperCamelCase			=      iterate_function(
      eval_quadratic_polynomial,
      c_cauliflower,
      nb_iterations,
      z_a,
      infinity=1.1 * escape_radius,
  )
  show_results("""z^2+c""", c_cauliflower, escape_radius, z_final)

  UpperCamelCase			=      64
  UpperCamelCase			=      2 * abs(c_polynomial_a) + 1
  UpperCamelCase			=      iterate_function(
      eval_quadratic_polynomial,
      c_polynomial_a,
      nb_iterations,
      z_a,
      infinity=1.1 * escape_radius,
  )
  show_results("""z^2+c""", c_polynomial_a, escape_radius, z_final)

  UpperCamelCase			=      1_61
  UpperCamelCase			=      2 * abs(c_polynomial_a) + 1
  UpperCamelCase			=      iterate_function(
      eval_quadratic_polynomial,
      c_polynomial_a,
      nb_iterations,
      z_a,
      infinity=1.1 * escape_radius,
  )
  show_results("""z^2+c""", c_polynomial_a, escape_radius, z_final)

  UpperCamelCase			=      12
  UpperCamelCase			=      10_000.0
  UpperCamelCase			=      iterate_function(
      eval_exponential,
      c_exponential,
      nb_iterations,
      z_a + 2,
      infinity=1.0e10,
  )
  show_results("""e^z+c""", c_exponential, escape_radius, z_final)






