




"""simple docstring"""






import string

import numpy







def      _snake_case			(				lowercase__							,    lowercase__		):
				return b if a == 0 else greatest_common_divisor(b % a							,    lowercase__		)






class lowerCAmelCase__	:






			'''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 lowercase						: x % 36						)

			lowerCamelCase__      =			numpy.vectorize(lowercase						)
			def __init__(  self  ,      lowercase  ):
							_lowerCamelCase     :			Optional[int]    =    self.modulus(lowercase  )  # mod36 calc's on the encrypt key
							self.check_determinant()  # validate the determinant of the encryption key
							_lowerCamelCase     :			Dict    =    encrypt_key.shape[0]
			def 					A_    (  self  ,      lowercase  ):
							return self.key_string.index(lowercase  )
			def 					A_    (  self  ,      lowercase  ):
							return self.key_string[round(lowercase  )]
			def 					A_    (  self  ):
							_lowerCamelCase     :			Optional[Any]    =    round(numpy.linalg.det(self.encrypt_key  )  )

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

							_lowerCamelCase     :			List[Any]    =    len(self.key_string  )
							if greatest_common_divisor(lowercase  ,      len(self.key_string  )  ) != 1:
											_lowerCamelCase     :			List[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(lowercase  )
			def 					A_    (  self  ,      lowercase  ):
							_lowerCamelCase     :			int    =    [char for char in text.upper() if char in self.key_string]

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

							return "".join(lowercase  )
			def 					A_    (  self  ,      lowercase  ):
							_lowerCamelCase     :			List[Any]    =    self.process_text(text.upper()  )
							_lowerCamelCase     :			Dict    =    ''

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

							return encrypted
			def 					A_    (  self  ):
							_lowerCamelCase     :			Tuple    =    round(numpy.linalg.det(self.encrypt_key  )  )

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

							_lowerCamelCase     :			Any    =    (
							    det_inv
							    * numpy.linalg.det(self.encrypt_key  )
							    * numpy.linalg.inv(self.encrypt_key  )
							)

							return self.to_int(self.modulus(lowercase  )  )






			def 					A_    (  self  ,      lowercase  ):
							_lowerCamelCase     :			Any    =    self.make_decrypt_key()
							_lowerCamelCase     :			List[Any]    =    self.process_text(text.upper()  )
							_lowerCamelCase     :			Any    =    ''

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

							return decrypted







def      _snake_case			(				):
				_lowerCamelCase     :			Optional[int]    =    int(input('Enter the order of the encryption key: '		)		)
				_lowerCamelCase     :			str    =    []

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

				_lowerCamelCase     :			Optional[int]    =    HillCipher(numpy.array(lowercase__		)		)

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


if __name__ == "__main__":
			import doctest

			doctest.testmod()

			main()





"""simple docstring"""






from ...configuration_utils import PretrainedConfig
from ...utils import logging


lowercase__     						=						logging.get_logger(__name__)

lowercase__     						=						{"""ctrl""": """https://huggingface.co/ctrl/resolve/main/config.json"""}






class lowerCAmelCase__	(     lowercase						):






			'''simple docstring'''



			lowerCamelCase__      =			"""ctrl"""
			lowerCamelCase__      =			["""past_key_values"""]
			lowerCamelCase__      =			{
			    """max_position_embeddings""": """n_positions""",
			    """hidden_size""": """n_embd""",
			    """num_attention_heads""": """n_head""",
			    """num_hidden_layers""": """n_layer""",
			}
			def __init__(  self  ,      lowercase=246534  ,      lowercase=256  ,      lowercase=1280  ,      lowercase=8192  ,      lowercase=48  ,      lowercase=16  ,      lowercase=0.1  ,      lowercase=0.1  ,      lowercase=1E-6  ,      lowercase=0.02  ,      lowercase=True  ,      **lowercase  ,      ):
							_lowerCamelCase     :			Any    =    vocab_size
							_lowerCamelCase     :			Dict    =    n_positions
							_lowerCamelCase     :			Optional[int]    =    n_embd
							_lowerCamelCase     :			str    =    n_layer
							_lowerCamelCase     :			Union[str, Any]    =    n_head
							_lowerCamelCase     :			Any    =    dff
							_lowerCamelCase     :			int    =    resid_pdrop
							_lowerCamelCase     :			Dict    =    embd_pdrop
							_lowerCamelCase     :			Union[str, Any]    =    layer_norm_epsilon
							_lowerCamelCase     :			Tuple    =    initializer_range

							_lowerCamelCase     :			str    =    use_cache

							super().__init__(**lowercase  )