





"""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    :						Union[str, Any]						 =     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    :						int						 =     round(numpy.linalg.det(self.encrypt_key  )  )

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

     __A    :						Dict						 =     len(self.key_string  )
     if greatest_common_divisor(__lowerCamelCase					,						len(self.key_string  )  ) != 1:
         __A    :						Optional[Any]						 =     (
             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    :						List[str]						 =     [char for char in text.upper() if char in self.key_string]

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

     return "".join(__lowerCamelCase  )

 def 					UpperCamelCase__(    self					,						__lowerCamelCase  ):



     '''simple docstring'''




     __A    :						Optional[int]						 =     self.process_text(text.upper()  )
     __A    :						Union[str, Any]						 =     ''''''

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

     return encrypted

 def 					UpperCamelCase__(    self  ):



     '''simple docstring'''




     __A    :						List[str]						 =     round(numpy.linalg.det(self.encrypt_key  )  )

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

     __A    :						Optional[Any]						 =     (
         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    :						Tuple						 =     self.make_decrypt_key()
     __A    :						Tuple						 =     self.process_text(text.upper()  )
     __A    :						List[str]						 =     ''''''

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

     return decrypted







def 		__lowercase     (   )   ->None:



    '''simple docstring'''







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

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

    __A    :						Any						 =     HillCipher(numpy.array(snake_case_						)						)

    print('''Would you like to encrypt or decrypt some text? (1 or 2)'''						)
    __A    :						Optional[int]						 =     input('''\n1. Encrypt\n2. Decrypt\n'''						)
    if option == "1":
        __A    :						List[str]						 =     input('''What text would you like to encrypt?: '''						)
        print('''Your encrypted text is:'''						)
        print(hc.encrypt(snake_case_						)						)
    elif option == "2":
        __A    :						List[Any]						 =     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"""



import logging

from transformers.configuration_utils import PretrainedConfig


a_ =			logging.getLogger(__name__)






class 		__snake_case					(		SCREAMING_SNAKE_CASE__     ):





 """simple docstring"""


 _lowerCamelCase        =     """masked_bert"""

 def __init__(    self					,						__lowerCamelCase=3_0522					,						__lowerCamelCase=768					,						__lowerCamelCase=12					,						__lowerCamelCase=12					,						__lowerCamelCase=3072					,						__lowerCamelCase="gelu"					,						__lowerCamelCase=0.1					,						__lowerCamelCase=0.1					,						__lowerCamelCase=512					,						__lowerCamelCase=2					,						__lowerCamelCase=0.0_2					,						__lowerCamelCase=1e-1_2					,						__lowerCamelCase=0					,						__lowerCamelCase="topK"					,						__lowerCamelCase="constant"					,						__lowerCamelCase=0.0					,						**__lowerCamelCase					,						):



     '''simple docstring'''




     super().__init__(pad_token_id=__lowerCamelCase					,						**__lowerCamelCase  )

     __A    :						Dict						 =     vocab_size
     __A    :						Union[str, Any]						 =     hidden_size
     __A    :						Tuple						 =     num_hidden_layers
     __A    :						Tuple						 =     num_attention_heads
     __A    :						Optional[Any]						 =     hidden_act
     __A    :						List[str]						 =     intermediate_size
     __A    :						Any						 =     hidden_dropout_prob
     __A    :						Optional[Any]						 =     attention_probs_dropout_prob
     __A    :						Any						 =     max_position_embeddings
     __A    :						str						 =     type_vocab_size
     __A    :						List[Any]						 =     initializer_range
     __A    :						str						 =     layer_norm_eps
     __A    :						Optional[int]						 =     pruning_method
     __A    :						str						 =     mask_init
     __A    :						Any						 =     mask_scale




