


"""simple docstring"""
from __future__ import annotations

def 							_snake_case			(      __snake_case       :			str	,   __snake_case       :			dict[str, str]      ):




			"""simple docstring"""







			_lowerCamelCase  :				Any      =		'', '', ''
			_lowerCamelCase  :				Optional[Any]      =		[]

			for character in message_part:
						tmp.append(character_to_number[character]      )

			for each in tmp:
						one += each[0]
						two += each[1]
						three += each[2]

			return one + two + three

def 							_snake_case			(      __snake_case       :			str	,   __snake_case       :			dict[str, str]      ):




			"""simple docstring"""







			_lowerCamelCase  :				Tuple      =		'', ''
			_lowerCamelCase  :				Optional[Any]      =		[]

			for character in message_part:
						this_part += character_to_number[character]

			for digit in this_part:
						tmp += digit
						if len(lowercase_      ) == len(lowercase_      ):
									result.append(lowercase_      )
									_lowerCamelCase  :				Dict      =		''

			return result[0], result[1], result[2]

def 							_snake_case			(      __snake_case       :			str	,   __snake_case       :			str      ):




			"""simple docstring"""







			_lowerCamelCase  :				Optional[int]      =		alphabet.replace(""" """	,   """"""      ).upper()
			_lowerCamelCase  :				Any      =		message.replace(""" """	,   """"""      ).upper()

			# Check length and characters
			if len(lowercase_      ) != 27:
						raise KeyError("""Length of alphabet has to be 27."""      )
			for each in message:
						if each not in alphabet:
									raise ValueError("""Each message character has to be included in alphabet!"""      )

    # Generate dictionares
			_lowerCamelCase  :				Any      =		(
			    '111',
			    '112',
			    '113',
			    '121',
			    '122',
			    '123',
			    '131',
			    '132',
			    '133',
			    '211',
			    '212',
			    '213',
			    '221',
			    '222',
			    '223',
			    '231',
			    '232',
			    '233',
			    '311',
			    '312',
			    '313',
			    '321',
			    '322',
			    '323',
			    '331',
			    '332',
			    '333',
			)
			_lowerCamelCase  :				Union[str, Any]      =		{}
			_lowerCamelCase  :				Union[str, Any]      =		{}
			for letter, number in zip(lowercase_	,   lowercase_      ):
						_lowerCamelCase  :				List[str]      =		number
						_lowerCamelCase  :				str      =		letter

			return message, alphabet, character_to_number, number_to_character

def 							_snake_case			(      __snake_case       :			str	,   __snake_case       :			str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ."	,   __snake_case       :			int = 5      ):




			"""simple docstring"""







			_lowerCamelCase  :				int      =		__prepare(
			    lowercase_	,   lowercase_      )
			_lowerCamelCase  :				List[Any]      =		'', ''

			for i in range(0	,   len(lowercase_      ) + 1	,   lowercase_      ):
						encrypted_numeric += __encrypt_part(
						    message[i : i + period]	,   lowercase_      )

			for i in range(0	,   len(lowercase_      )	,   3      ):
						encrypted += number_to_character[encrypted_numeric[i : i + 3]]

			return encrypted

def 							_snake_case			(      __snake_case       :			str	,   __snake_case       :			str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ."	,   __snake_case       :			int = 5      ):




			"""simple docstring"""







			_lowerCamelCase  :				Optional[int]      =		__prepare(
			    lowercase_	,   lowercase_      )
			_lowerCamelCase  :				Union[str, Any]      =		[]
			_lowerCamelCase  :				Optional[Any]      =		''

			for i in range(0	,   len(lowercase_      ) + 1	,   lowercase_      ):
						_lowerCamelCase  :				str      =		__decrypt_part(message[i : i + period]	,   lowercase_      )

						for j in range(0	,   len(lowercase_      )      ):
									decrypted_numeric.append(a[j] + b[j] + c[j]      )

			for each in decrypted_numeric:
						decrypted += number_to_character[each]

			return decrypted


if __name__ == "__main__":
	UpperCAmelCase   =	"""DEFEND THE EAST WALL OF THE CASTLE."""
	UpperCAmelCase   =	encrypt_message(msg, """EPSDUCVWYM.ZLKXNBTFGORIJHAQ""")
	UpperCAmelCase   =	decrypt_message(encrypted, """EPSDUCVWYM.ZLKXNBTFGORIJHAQ""")
	print(f'''Encrypted: {encrypted}\nDecrypted: {decrypted}''')





"""simple docstring"""
import timeit




class   lowercase__							:





   def __init__(       self			,      SCREAMING_SNAKE_CASE)     ->     Tuple:
      if isinstance(SCREAMING_SNAKE_CASE			,      SCREAMING_SNAKE_CASE):  # Initializes a matrix identical to the one provided.
         _lowerCamelCase  :				List[str]      =		arg
         _lowerCamelCase  :				List[str]      =		len(SCREAMING_SNAKE_CASE)
      else:  # Initializes a square matrix of the given size and set values to zero.
         _lowerCamelCase  :				List[Any]      =		arg
         _lowerCamelCase  :				Union[str, Any]      =		[[0 for _ in range(self.n)] for _ in range(self.n)]





   def __mul__(       self			,      SCREAMING_SNAKE_CASE)     ->     Optional[Any]:
      _lowerCamelCase  :				List[Any]      =		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 							_snake_case			(      __snake_case       :			Union[str, Any]	,   __snake_case       :			List[Any]      ):




   """simple docstring"""







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

def 							_snake_case			(      __snake_case       :			List[str]	,   __snake_case       :			str	,   __snake_case       :			List[Any]      ):




   """simple docstring"""







   if n == 1:
      return fa
   elif n == 2:
      return fa
   _lowerCamelCase  :				Any      =		Matrix([[1, 1], [1, 0]]      )
   _lowerCamelCase  :				List[str]      =		modular_exponentiation(__snake_case	,   n - 2      )
   return fa * matrix.t[0][0] + fa * matrix.t[0][1]

def 							_snake_case			(      __snake_case       :			int	,   __snake_case       :			Optional[int]	,   __snake_case       :			List[Any]      ):




   """simple docstring"""







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

   _lowerCamelCase  :				Optional[Any]      =		fa
   _lowerCamelCase  :				int      =		fa
   n -= 2

   while n > 0:
      _lowerCamelCase      ,						_lowerCamelCase  :				Tuple      =		fn_a + fn_a, fn_a
      n -= 1

   return fn_a

def 							_snake_case			(      ):




   """simple docstring"""







   _lowerCamelCase  :				List[str]      =		"""
from random import randint
from __main__ import fibonacci_with_matrix_exponentiation
"""
   _lowerCamelCase  :				int      =		"""fibonacci_with_matrix_exponentiation(randint(1,70000), 1, 1)"""
   _lowerCamelCase  :				Tuple      =		timeit.timeit(setup=__snake_case	,   stmt=__snake_case	,   number=100      )
   print("""With matrix exponentiation the average execution time is """	,   exec_time / 100      )
   return exec_time

def 							_snake_case			(      ):




   """simple docstring"""







   _lowerCamelCase  :				Dict      =		"""
from random import randint
from __main__ import simple_fibonacci
"""
   _lowerCamelCase  :				Optional[int]      =		"""simple_fibonacci(randint(1,70000), 1, 1)"""
   _lowerCamelCase  :				List[Any]      =		timeit.timeit(setup=__snake_case	,   stmt=__snake_case	,   number=100      )
   print(
       """Without matrix exponentiation the average execution time is """	,   exec_time / 100      )
   return exec_time

def 							_snake_case			(      ):




   """simple docstring"""







   matrix_exponentiation_time()
   simple_fibonacci_time()


if __name__ == "__main__":
 main()

