



"""simple docstring"""






import string

import numpy


def      _lowercase							(    __snake_case   ,__snake_case      )		->  int:
			return b if a == 0 else greatest_common_divisor(b % a   ,__snake_case      )



class      A__  :




	'''simple docstring'''





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

	SCREAMING_SNAKE_CASE        =      numpy.vectorize(__SCREAMING_SNAKE_CASE				)

	def __init__(	self:						int			,     _SCREAMING_SNAKE_CASE:						numpy.ndarray)							->			None:

				"""simple docstring"""

				__lowerCAmelCase :    Optional[Any]				=			self.modulus(_SCREAMING_SNAKE_CASE)  # mod36 calc's on the encrypt key
				self.check_determinant()  # validate the determinant of the encryption key
				__lowerCAmelCase :    Optional[int]				=			encrypt_key.shape[0]

	def 				_SCREAMING_SNAKE_CASE  (	self:						Any			,     _SCREAMING_SNAKE_CASE:						str)							->			int:

				"""simple docstring"""

				return self.key_string.index(_SCREAMING_SNAKE_CASE)

	def 				_SCREAMING_SNAKE_CASE  (	self:						str			,     _SCREAMING_SNAKE_CASE:						int)							->			str:

				"""simple docstring"""

				return self.key_string[round(_SCREAMING_SNAKE_CASE)]

	def 				_SCREAMING_SNAKE_CASE  (	self:						int)							->			None:

				"""simple docstring"""

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

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

				__lowerCAmelCase :    Optional[Any]				=			len(self.key_string)
				if greatest_common_divisor(_SCREAMING_SNAKE_CASE			,     len(self.key_string)) != 1:
							__lowerCAmelCase :    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 				_SCREAMING_SNAKE_CASE  (	self:						Optional[int]			,     _SCREAMING_SNAKE_CASE:						str)							->			str:

				"""simple docstring"""

				__lowerCAmelCase :    Dict				=			[char for char in text.upper() if char in self.key_string]

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

				return "".join(_SCREAMING_SNAKE_CASE)

	def 				_SCREAMING_SNAKE_CASE  (	self:						Tuple			,     _SCREAMING_SNAKE_CASE:						str)							->			str:

				"""simple docstring"""

				__lowerCAmelCase :    Dict				=			self.process_text(text.upper())
				__lowerCAmelCase :    Tuple				=			""

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

				return encrypted

	def 				_SCREAMING_SNAKE_CASE  (	self:						str)							->			numpy.ndarray:

				"""simple docstring"""

				__lowerCAmelCase :    Tuple				=			round(numpy.linalg.det(self.encrypt_key))

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

				__lowerCAmelCase :    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 				_SCREAMING_SNAKE_CASE  (	self:						Any			,     _SCREAMING_SNAKE_CASE:						str)							->			str:

				"""simple docstring"""

				__lowerCAmelCase :    Dict				=			self.make_decrypt_key()
				__lowerCAmelCase :    Optional[int]				=			self.process_text(text.upper())
				__lowerCAmelCase :    Optional[Any]				=			""

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

				return decrypted






def      _lowercase							(    )		->  None:
			__lowerCAmelCase :    List[Any]				=			int(input("Enter the order of the encryption key: "      )      )
			__lowerCAmelCase :    Optional[Any]				=			[]

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

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

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