


'''simple docstring'''

import timeit







class        UpperCAmelCase       :

 def __init__(       self       :		List[str],    a_       :		str    ):





    """simple docstring"""



    if isinstance(a_,    a_    ):  # Initializes a matrix identical to the one provided.
       UpperCamelCase__         =  arg
       UpperCamelCase__         =  len(a_    )
    else:  # Initializes a square matrix of the given size and set values to zero.
       UpperCamelCase__         =  arg
       UpperCamelCase__         =  [[0 for _ in range(self.n    )] for _ in range(self.n    )]

 def __mul__(       self       :		List[str],    a_       :		List[str]    ):





    """simple docstring"""



    UpperCamelCase__         =  Matrix(self.n    )
    for i in range(self.n    ):
       for j in range(self.n    ):
          for k in range(self.n    ):
             matrix.t[i][j] += self.t[i][k] * b.t[k][j]
    return matrix







def 				SCREAMING_SNAKE_CASE__(						_UpperCamelCase					: str			,						_UpperCamelCase					: Optional[Any]      )						->    int:





   '''simple docstring'''







   UpperCamelCase__         =  Matrix([[1, 0], [0, 1]]      )
   while b > 0:
      if b & 1:
         matrix *= a
      a *= a
      b >>= 1
   return matrix



def 				SCREAMING_SNAKE_CASE__(						_UpperCamelCase					: Dict			,						_UpperCamelCase					: List[str]			,						_UpperCamelCase					: int      )						->    int:





   '''simple docstring'''







   if n == 1:
      return fa
   elif n == 2:
      return fa
   UpperCamelCase__         =  Matrix([[1, 1], [1, 0]]      )
   UpperCamelCase__         =  modular_exponentiation(_UpperCamelCase			,						n - 2      )
   return fa * matrix.t[0][0] + fa * matrix.t[0][1]



def 				SCREAMING_SNAKE_CASE__(						_UpperCamelCase					: Dict			,						_UpperCamelCase					: Union[str, Any]			,						_UpperCamelCase					: Union[str, Any]      )						->    Dict:





   '''simple docstring'''







   if n == 1:
      return fa
   elif n == 2:
      return fa

   UpperCamelCase__         =  fa
   UpperCamelCase__         =  fa
   n -= 2

   while n > 0:
      UpperCamelCase__         =  fn_a + fn_a, fn_a
      n -= 1

   return fn_a



def 				SCREAMING_SNAKE_CASE__(						)						->    Union[str, Any]:





   '''simple docstring'''







   UpperCamelCase__         =  '''
from random import randint
from __main__ import fibonacci_with_matrix_exponentiation
'''
   UpperCamelCase__         =  '''fibonacci_with_matrix_exponentiation(randint(1,70000), 1, 1)'''
   UpperCamelCase__         =  timeit.timeit(setup=_UpperCamelCase			,						stmt=_UpperCamelCase			,						number=1_00      )
   print("With matrix exponentiation the average execution time is "			,						exec_time / 1_00      )
   return exec_time



def 				SCREAMING_SNAKE_CASE__(						)						->    Any:





   '''simple docstring'''







   UpperCamelCase__         =  '''
from random import randint
from __main__ import simple_fibonacci
'''
   UpperCamelCase__         =  '''simple_fibonacci(randint(1,70000), 1, 1)'''
   UpperCamelCase__         =  timeit.timeit(setup=_UpperCamelCase			,						stmt=_UpperCamelCase			,						number=1_00      )
   print(
       "Without matrix exponentiation the average execution time is "			,						exec_time / 1_00      )
   return exec_time



def 				SCREAMING_SNAKE_CASE__(						)						->    str:





   '''simple docstring'''







   matrix_exponentiation_time()
   simple_fibonacci_time()


if __name__ == "__main__":
       main()





import random
import sys

from . import cryptomath_module as cryptomath

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







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







def  lowerCAmelCase  (	UpperCAmelCase,	UpperCAmelCase       )  ->str:






					"""simple docstring"""






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







def  lowerCAmelCase  (	UpperCAmelCase,	UpperCAmelCase       )  ->str:






					"""simple docstring"""






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







def  lowerCAmelCase  (	)  ->int:






					"""simple docstring"""






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







def  lowerCAmelCase  (	)  ->None:






					"""simple docstring"""






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

					if mode.startswith('''e'''       ):
										__magic_name__					:							Any		   =							'''encrypt'''
										__magic_name__					:							Any		   =							encrypt_message(UpperCAmelCase,	UpperCAmelCase       )
					elif mode.startswith('''d'''       ):
										__magic_name__					:							Optional[Any]		   =							'''decrypt'''
										__magic_name__					:							Union[str, Any]		   =							decrypt_message(UpperCAmelCase,	UpperCAmelCase       )
					print(F'''\n{mode.title()}ed text: \n{translated}'''       )


if __name__ == "__main__":
				import doctest

				doctest.testmod()
				# main()



