
"""simple docstring"""






import string

import numpy




def __magic_name__	(				_lowerCamelCase:		int,					_lowerCamelCase:		int			)					->						int:

	'''simple docstring'''




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



class 			lowercase					:
			lowercase        =     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)
			lowercase        =     numpy.vectorize(lambda lowercase__		: x % 36		)

			lowercase        =     numpy.vectorize(lowercase__		)






			def __init__(self  :	str      ,SCREAMING_SNAKE_CASE_  :	numpy.ndarray			)       ->	None:





				"""simple docstring"""


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






			def 					UpperCAmelCase							(self  :	Optional[int]      ,SCREAMING_SNAKE_CASE_  :	str			)       ->	int:





				"""simple docstring"""


				return self.key_string.index(SCREAMING_SNAKE_CASE_			)






			def 					UpperCAmelCase							(self  :	Optional[Any]      ,SCREAMING_SNAKE_CASE_  :	int			)       ->	str:





				"""simple docstring"""


				return self.key_string[round(SCREAMING_SNAKE_CASE_			)]






			def 					UpperCAmelCase							(self  :	int			)       ->	None:





				"""simple docstring"""


				lowerCAmelCase												=  round(numpy.linalg.det(self.encrypt_key			)			)

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

				lowerCAmelCase												=  len(self.key_string			)
				if greatest_common_divisor(SCREAMING_SNAKE_CASE_      ,len(self.key_string			)			) != 1:
					lowerCAmelCase												=  (
					    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 					UpperCAmelCase							(self  :	List[str]      ,SCREAMING_SNAKE_CASE_  :	str			)       ->	str:





				"""simple docstring"""


				lowerCAmelCase												=  [char for char in text.upper() if char in self.key_string]

				lowerCAmelCase												=  chars[-1]
				while len(SCREAMING_SNAKE_CASE_			) % self.break_key != 0:
					chars.append(SCREAMING_SNAKE_CASE_			)

				return "".join(SCREAMING_SNAKE_CASE_			)






			def 					UpperCAmelCase							(self  :	Optional[int]      ,SCREAMING_SNAKE_CASE_  :	str			)       ->	str:





				"""simple docstring"""


				lowerCAmelCase												=  self.process_text(text.upper()			)
				lowerCAmelCase												=  ''''''

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

				return encrypted






			def 					UpperCAmelCase							(self  :	Tuple			)       ->	numpy.ndarray:





				"""simple docstring"""


				lowerCAmelCase												=  round(numpy.linalg.det(self.encrypt_key			)			)

				if det < 0:
					lowerCAmelCase												=  det % len(self.key_string			)
				lowerCAmelCase												=  None
				for i in range(len(self.key_string			)			):
					if (det * i) % len(self.key_string			) == 1:
						lowerCAmelCase												=  i
						break

				lowerCAmelCase												=  (
				    det_inv
				    * numpy.linalg.det(self.encrypt_key			)
				    * numpy.linalg.inv(self.encrypt_key			)
				)

				return self.to_int(self.modulus(SCREAMING_SNAKE_CASE_			)			)






			def 					UpperCAmelCase							(self  :	List[str]      ,SCREAMING_SNAKE_CASE_  :	str			)       ->	str:





				"""simple docstring"""


				lowerCAmelCase												=  self.make_decrypt_key()
				lowerCAmelCase												=  self.process_text(text.upper()			)
				lowerCAmelCase												=  ''''''

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

				return decrypted





def __magic_name__	(				)					->						None:

	'''simple docstring'''




	lowerCAmelCase												=  int(input('''Enter the order of the encryption key: '''			)			)
	lowerCAmelCase												=  []

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

	lowerCAmelCase												=  HillCipher(numpy.array(_lowerCamelCase			)			)

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


if __name__ == "__main__":
					import doctest

					doctest.testmod()

					main()




"""simple docstring"""






from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_flax_available,
    is_tf_available,
    is_torch_available,
)


UpperCAmelCase        =				{
    """configuration_roberta_prelayernorm""": [
        """ROBERTA_PRELAYERNORM_PRETRAINED_CONFIG_ARCHIVE_MAP""",
        """RobertaPreLayerNormConfig""",
        """RobertaPreLayerNormOnnxConfig""",
    ],
}

try:
					if not is_torch_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					UpperCAmelCase        =				[
					    """ROBERTA_PRELAYERNORM_PRETRAINED_MODEL_ARCHIVE_LIST""",
					    """RobertaPreLayerNormForCausalLM""",
					    """RobertaPreLayerNormForMaskedLM""",
					    """RobertaPreLayerNormForMultipleChoice""",
					    """RobertaPreLayerNormForQuestionAnswering""",
					    """RobertaPreLayerNormForSequenceClassification""",
					    """RobertaPreLayerNormForTokenClassification""",
					    """RobertaPreLayerNormModel""",
					    """RobertaPreLayerNormPreTrainedModel""",
					]

try:
					if not is_tf_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					UpperCAmelCase        =				[
					    """TF_ROBERTA_PRELAYERNORM_PRETRAINED_MODEL_ARCHIVE_LIST""",
					    """TFRobertaPreLayerNormForCausalLM""",
					    """TFRobertaPreLayerNormForMaskedLM""",
					    """TFRobertaPreLayerNormForMultipleChoice""",
					    """TFRobertaPreLayerNormForQuestionAnswering""",
					    """TFRobertaPreLayerNormForSequenceClassification""",
					    """TFRobertaPreLayerNormForTokenClassification""",
					    """TFRobertaPreLayerNormMainLayer""",
					    """TFRobertaPreLayerNormModel""",
					    """TFRobertaPreLayerNormPreTrainedModel""",
					]

try:
					if not is_flax_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					UpperCAmelCase        =				[
					    """FlaxRobertaPreLayerNormForCausalLM""",
					    """FlaxRobertaPreLayerNormForMaskedLM""",
					    """FlaxRobertaPreLayerNormForMultipleChoice""",
					    """FlaxRobertaPreLayerNormForQuestionAnswering""",
					    """FlaxRobertaPreLayerNormForSequenceClassification""",
					    """FlaxRobertaPreLayerNormForTokenClassification""",
					    """FlaxRobertaPreLayerNormModel""",
					    """FlaxRobertaPreLayerNormPreTrainedModel""",
					]


if TYPE_CHECKING:
					from .configuration_roberta_prelayernorm import (
					    ROBERTA_PRELAYERNORM_PRETRAINED_CONFIG_ARCHIVE_MAP,
					    RobertaPreLayerNormConfig,
					    RobertaPreLayerNormOnnxConfig,
					)

					try:
										if not is_torch_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .modeling_roberta_prelayernorm import (
										    ROBERTA_PRELAYERNORM_PRETRAINED_MODEL_ARCHIVE_LIST,
										    RobertaPreLayerNormForCausalLM,
										    RobertaPreLayerNormForMaskedLM,
										    RobertaPreLayerNormForMultipleChoice,
										    RobertaPreLayerNormForQuestionAnswering,
										    RobertaPreLayerNormForSequenceClassification,
										    RobertaPreLayerNormForTokenClassification,
										    RobertaPreLayerNormModel,
										    RobertaPreLayerNormPreTrainedModel,
										)

					try:
										if not is_tf_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .modeling_tf_roberta_prelayernorm import (
										    TF_ROBERTA_PRELAYERNORM_PRETRAINED_MODEL_ARCHIVE_LIST,
										    TFRobertaPreLayerNormForCausalLM,
										    TFRobertaPreLayerNormForMaskedLM,
										    TFRobertaPreLayerNormForMultipleChoice,
										    TFRobertaPreLayerNormForQuestionAnswering,
										    TFRobertaPreLayerNormForSequenceClassification,
										    TFRobertaPreLayerNormForTokenClassification,
										    TFRobertaPreLayerNormMainLayer,
										    TFRobertaPreLayerNormModel,
										    TFRobertaPreLayerNormPreTrainedModel,
										)

					try:
										if not is_flax_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .modeling_flax_roberta_prelayernorm import (
										    FlaxRobertaPreLayerNormForCausalLM,
										    FlaxRobertaPreLayerNormForMaskedLM,
										    FlaxRobertaPreLayerNormForMultipleChoice,
										    FlaxRobertaPreLayerNormForQuestionAnswering,
										    FlaxRobertaPreLayerNormForSequenceClassification,
										    FlaxRobertaPreLayerNormForTokenClassification,
										    FlaxRobertaPreLayerNormModel,
										    FlaxRobertaPreLayerNormPreTrainedModel,
										)

else:
					import sys

					UpperCAmelCase        =				_LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)


