


'''simple docstring'''







import string

import numpy



def     _UpperCamelCase				(			UpperCamelCase__  , UpperCamelCase__		):






				"""simple docstring"""



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






class 		_snake_case     :






						'''simple docstring'''







						__snake_case				=   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)
						__snake_case				=   numpy.vectorize(lambda snake_case_		: x % 3_6		)

						__snake_case				=   numpy.vectorize(__SCREAMING_SNAKE_CASE		)







						def __init__(	self:						int   ,				__UpperCamelCase:						numpy.ndarray  )				->						None:
										__magic_name__					:       Optional[Any]    							=							self.modulus(_SCREAMING_SNAKE_CASE  )  # mod36 calc's on the encrypt key
										self.check_determinant()  # validate the determinant of the encryption key
										__magic_name__					:       Optional[int]    							=							encrypt_key.shape[0]







						def lowerCAmelCase__			(	self:						Any   ,				__UpperCamelCase:						str  )				->						int:
										return self.key_string.index(_SCREAMING_SNAKE_CASE  )







						def lowerCAmelCase__			(	self:						str   ,				__UpperCamelCase:						int  )				->						str:
										return self.key_string[round(_SCREAMING_SNAKE_CASE  )]







						def lowerCAmelCase__			(	self:						int  )				->						None:
										__magic_name__					:       Union[str, Any]    							=							round(numpy.linalg.det(self.encrypt_key  )  )

										if det < 0:
														__magic_name__					:       List[str]    							=							det % len(self.key_string  )

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

										__magic_name__					:       Tuple    							=							chars[-1]
										while len(_SCREAMING_SNAKE_CASE  ) % self.break_key != 0:
														chars.append(_SCREAMING_SNAKE_CASE  )

										return "".join(_SCREAMING_SNAKE_CASE  )







						def lowerCAmelCase__			(	self:						Tuple   ,				__UpperCamelCase:						str  )				->						str:
										__magic_name__					:       Dict    							=							self.process_text(text.upper()  )
										__magic_name__					:       Tuple    							=							""

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

										return encrypted







						def lowerCAmelCase__			(	self:						str  )				->						numpy.ndarray:
										__magic_name__					:       Tuple    							=							round(numpy.linalg.det(self.encrypt_key  )  )

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

										__magic_name__					:       List[str]    							=							(
										    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:						Any   ,				__UpperCamelCase:						str  )				->						str:
										__magic_name__					:       Dict    							=							self.make_decrypt_key()
										__magic_name__					:       Optional[int]    							=							self.process_text(text.upper()  )
										__magic_name__					:       Optional[Any]    							=							""

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

										return decrypted






def     _UpperCamelCase				(			):






				"""simple docstring"""



				__magic_name__					:       List[Any]    							=							int(input("Enter the order of the encryption key: "		)		)
				__magic_name__					:       Optional[Any]    							=							[]

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

				__magic_name__					:       Union[str, Any]    							=							HillCipher(numpy.array(__snake_case		)		)

				print("Would you like to encrypt or decrypt some text? (1 or 2)"		)
				__magic_name__					:       Union[str, Any]    							=							input("\n1. Encrypt\n2. Decrypt\n"		)
				if option == "1":
								__magic_name__					:       Optional[Any]    							=							input("What text would you like to encrypt?: "		)
								print("Your encrypted text is:"		)
								print(hc.encrypt(__snake_case		)		)
				elif option == "2":
								__magic_name__					:       str    							=							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 (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_sentencepiece_available,
    is_tokenizers_available,
    is_torch_available,
)


__snake_case				:  int =       {'configuration_plbart': ['PLBART_PRETRAINED_CONFIG_ARCHIVE_MAP', 'PLBartConfig']}

try:
	if not is_sentencepiece_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	__snake_case				:  Optional[Any] =       ['PLBartTokenizer']

try:
	if not is_torch_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	__snake_case				:  List[str] =       [
	    'PLBART_PRETRAINED_MODEL_ARCHIVE_LIST',
	    'PLBartForCausalLM',
	    'PLBartForConditionalGeneration',
	    'PLBartForSequenceClassification',
	    'PLBartModel',
	    'PLBartPreTrainedModel',
	]


if TYPE_CHECKING:
	from .configuration_plbart import PLBART_PRETRAINED_CONFIG_ARCHIVE_MAP, PLBartConfig

	try:
		if not is_sentencepiece_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .tokenization_plbart import PLBartTokenizer

	try:
		if not is_torch_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .modeling_plbart import (
		    PLBART_PRETRAINED_MODEL_ARCHIVE_LIST,
		    PLBartForCausalLM,
		    PLBartForConditionalGeneration,
		    PLBartForSequenceClassification,
		    PLBartModel,
		    PLBartPreTrainedModel,
		)


else:
	import sys

	__snake_case				:  Any =       _LazyModule(__name__, globals()['__file__'], _import_structure)