



import string

import numpy





def 					__snake_case     (      _UpperCAmelCase       ,			_UpperCAmelCase    ):
    return b if a == 0 else greatest_common_divisor(b % a       ,			_UpperCAmelCase    )

class    _A	:
       UpperCamelCase__  :   List[Any]						 =						string.ascii_uppercase + string.digits
       # This cipher takes alphanumerics into account
       # i.e. a total of 36 characters

       # take x and return x % len(key_string)
       UpperCamelCase__  :   Optional[int]						 =						numpy.vectorize(lambda __UpperCAmelCase   : x % 36   )

       UpperCamelCase__  :   Tuple						 =						numpy.vectorize(__UpperCAmelCase   )



       def __init__(		self							:					Any					,		__SCREAMING_SNAKE_CASE							:					numpy.ndarray):


           '''simple docstring'''

           __a							=    self.modulus(__SCREAMING_SNAKE_CASE)  # mod36 calc's on the encrypt key
           self.check_determinant()  # validate the determinant of the encryption key
           __a							=    encrypt_key.shape[0]



       def 		_lowerCamelCase      (		self							:					Optional[int]					,		__SCREAMING_SNAKE_CASE							:					str):


           '''simple docstring'''

           return self.key_string.index(__SCREAMING_SNAKE_CASE)



       def 		_lowerCamelCase      (		self							:					Tuple					,		__SCREAMING_SNAKE_CASE							:					int):


           '''simple docstring'''

           return self.key_string[round(__SCREAMING_SNAKE_CASE)]



       def 		_lowerCamelCase      (		self							:					Optional[Any]):


           '''simple docstring'''

           __a							=    round(numpy.linalg.det(self.encrypt_key))

           if det < 0:
               __a							=    det % len(self.key_string)

           __a							=    len(self.key_string)
           if greatest_common_divisor(__SCREAMING_SNAKE_CASE					,		len(self.key_string)) != 1:
               __a							=    (
                   F'determinant modular {req_l} of encryption key({det}) '
                   F'is not co prime w.r.t {req_l}.\nTry another key.'
               )
               raise ValueError(__SCREAMING_SNAKE_CASE)



       def 		_lowerCamelCase      (		self							:					Dict					,		__SCREAMING_SNAKE_CASE							:					str):


           '''simple docstring'''

           __a							=    [char for char in text.upper() if char in self.key_string]

           __a							=    chars[-1]
           while len(__SCREAMING_SNAKE_CASE) % self.break_key != 0:
               chars.append(__SCREAMING_SNAKE_CASE)

           return "".join(__SCREAMING_SNAKE_CASE)



       def 		_lowerCamelCase      (		self							:					Any					,		__SCREAMING_SNAKE_CASE							:					str):


           '''simple docstring'''

           __a							=    self.process_text(text.upper())
           __a							=    ''''''

           for i in range(0					,		len(__SCREAMING_SNAKE_CASE) - self.break_key + 1					,		self.break_key):
               __a							=    text[i : i + self.break_key]
               __a							=    [self.replace_letters(__SCREAMING_SNAKE_CASE) for char in batch]
               __a							=    numpy.array([vec]).T
               __a							=    self.modulus(self.encrypt_key.dot(__SCREAMING_SNAKE_CASE)).T.tolist()[
                   0
               ]
               __a							=    ''''''.join(
                   self.replace_digits(__SCREAMING_SNAKE_CASE) for num in batch_encrypted)
               encrypted += encrypted_batch

           return encrypted



       def 		_lowerCamelCase      (		self							:					List[Any]):


           '''simple docstring'''

           __a							=    round(numpy.linalg.det(self.encrypt_key))

           if det < 0:
               __a							=    det % len(self.key_string)
           __a							=    None
           for i in range(len(self.key_string)):
               if (det * i) % len(self.key_string) == 1:
                   __a							=    i
                   break

           __a							=    (
               det_inv
               * numpy.linalg.det(self.encrypt_key)
               * numpy.linalg.inv(self.encrypt_key)
           )

           return self.to_int(self.modulus(__SCREAMING_SNAKE_CASE))





       def 		_lowerCamelCase      (		self							:					List[Any]					,		__SCREAMING_SNAKE_CASE							:					str):


           '''simple docstring'''

           __a							=    self.make_decrypt_key()
           __a							=    self.process_text(text.upper())
           __a							=    ''''''

           for i in range(0					,		len(__SCREAMING_SNAKE_CASE) - self.break_key + 1					,		self.break_key):
               __a							=    text[i : i + self.break_key]
               __a							=    [self.replace_letters(__SCREAMING_SNAKE_CASE) for char in batch]
               __a							=    numpy.array([vec]).T
               __a							=    self.modulus(decrypt_key.dot(__SCREAMING_SNAKE_CASE)).T.tolist()[0]
               __a							=    ''''''.join(
                   self.replace_digits(__SCREAMING_SNAKE_CASE) for num in batch_decrypted)
               decrypted += decrypted_batch

           return decrypted





def 					__snake_case     (      ):
    __a							=    int(input('''Enter the order of the encryption key: '''    )    )
    __a							=    []

    print('''Enter each row of the encryption key with space separated integers'''    )
    for _ in range(_UpperCAmelCase    ):
        __a							=    [int(_UpperCAmelCase    ) for x in input().split()]
        hill_matrix.append(_UpperCAmelCase    )

    __a							=    HillCipher(numpy.array(_UpperCAmelCase    )    )

    print('''Would you like to encrypt or decrypt some text? (1 or 2)'''    )
    __a							=    input('''\n1. Encrypt\n2. Decrypt\n'''    )
    if option == "1":
        __a							=    input('''What text would you like to encrypt?: '''    )
        print('''Your encrypted text is:'''    )
        print(hc.encrypt(_UpperCAmelCase    )    )
    elif option == "2":
        __a							=    input('''What text would you like to decrypt?: '''    )
        print('''Your decrypted text is:'''    )
        print(hc.decrypt(_UpperCAmelCase    )    )


if __name__ == "__main__":
 import doctest

 doctest.testmod()

 main()










def 					__snake_case     (      _UpperCAmelCase       ,			_UpperCAmelCase    ):
    return base * power(_UpperCAmelCase       ,			(exponent - 1)    ) if exponent else 1


if __name__ == "__main__":
 print('''Raise base to the power of exponent using recursion...''')
 __snake_case						:List[Any]						=					int(input('''Enter the base: ''').strip())
 __snake_case						:Dict						=					int(input('''Enter the exponent: ''').strip())
 __snake_case						:int						=					power(base, abs(exponent))
 if exponent < 0:  # power() does not properly deal w/ negative exponents
  __snake_case						:Optional[Any]						=					1 / result
 print(f'{base} to the power of {exponent} is {result}')





