





"""simple docstring"""



import string

import numpy







def 		__lowercase					(       snake_case_  :  int    ,snake_case_  :  int						)       ->int:



    '''simple docstring'''







    return b if a == 0 else greatest_common_divisor(b % a    ,snake_case_						)






class 		__snake_case :





 """simple docstring"""


 _lowerCamelCase				=					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)
 _lowerCamelCase				=					numpy.vectorize(lambda SCREAMING_SNAKE_CASE__					: x % 36					)

 _lowerCamelCase				=					numpy.vectorize(SCREAMING_SNAKE_CASE__					)

 def __init__(   self ,						__lowerCamelCase  ):



     '''simple docstring'''




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

 def  UpperCamelCase__(   self ,						__lowerCamelCase  ):



     '''simple docstring'''




     return self.key_string.index(__lowerCamelCase  )

 def  UpperCamelCase__(   self ,						__lowerCamelCase  ):



     '''simple docstring'''




     return self.key_string[round(__lowerCamelCase  )]

 def  UpperCamelCase__(   self  ):



     '''simple docstring'''




     __A   :						Union[str, Any]									=					round(numpy.linalg.det(self.encrypt_key  )  )

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

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

 def  UpperCamelCase__(   self ,						__lowerCamelCase  ):



     '''simple docstring'''




     __A   :						Optional[int]									=					[char for char in text.upper() if char in self.key_string]

     __A   :						List[Any]									=					chars[-1]
     while len(__lowerCamelCase  ) % self.break_key != 0:
         chars.append(__lowerCamelCase  )

     return "".join(__lowerCamelCase  )

 def  UpperCamelCase__(   self ,						__lowerCamelCase  ):



     '''simple docstring'''




     __A   :						Optional[Any]									=					self.process_text(text.upper()  )
     __A   :						Dict									=					''''''

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

     return encrypted

 def  UpperCamelCase__(   self  ):



     '''simple docstring'''




     __A   :						Union[str, Any]									=					round(numpy.linalg.det(self.encrypt_key  )  )

     if det < 0:
         __A   :						List[str]									=					det % len(self.key_string  )
     __A   :						int									=					None
     for i in range(len(self.key_string  )  ):
         if (det * i) % len(self.key_string  ) == 1:
             __A   :						int									=					i
             break

     __A   :						Optional[int]									=					(
         det_inv
         * numpy.linalg.det(self.encrypt_key  )
         * numpy.linalg.inv(self.encrypt_key  )
     )

     return self.to_int(self.modulus(__lowerCamelCase  )  )







 def  UpperCamelCase__(   self ,						__lowerCamelCase  ):



     '''simple docstring'''




     __A   :						str									=					self.make_decrypt_key()
     __A   :						Tuple									=					self.process_text(text.upper()  )
     __A   :						str									=					''''''

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

     return decrypted







def 		__lowercase					(       )       ->None:



    '''simple docstring'''







    __A   :						Optional[Any]									=					int(input('''Enter the order of the encryption key: '''						)						)
    __A   :						int									=					[]

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

    __A   :						Optional[int]									=					HillCipher(numpy.array(snake_case_						)						)

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


if __name__ == "__main__":
       import doctest

       doctest.testmod()

       main()











"""simple docstring"""



from typing import TYPE_CHECKING

from ....utils import _LazyModule


a_			=      {"""tokenization_tapex""": ["""TapexTokenizer"""]}


if TYPE_CHECKING:
       from .tokenization_tapex import TapexTokenizer


else:
       import sys

       a_			=      _LazyModule(__name__, globals()["""__file__"""], _import_structure)




