






import string

import numpy




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

class        lowerCAmelCase_				:







				"""simple docstring"""




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

				_snake_case				:   Optional[Any]        =			numpy.vectorize(lowercase	)







				def __init__( self     :Optional[Any]  ,     lowerCamelCase__     :numpy.ndarray     ):
					UpperCamelCase__ :Dict						=      self.modulus(lowerCamelCase__     )  # mod36 calc's on the encrypt key
					self.check_determinant()  # validate the determinant of the encryption key
					UpperCamelCase__ :Any						=      encrypt_key.shape[0]







				def 				__a   ( self     :List[Any]  ,     lowerCamelCase__     :str     ):
					return self.key_string.index(lowerCamelCase__     )







				def 				__a   ( self     :List[Any]  ,     lowerCamelCase__     :int     ):
					return self.key_string[round(lowerCamelCase__     )]







				def 				__a   ( self     :List[str]     ):
					UpperCamelCase__ :Optional[Any]						=      round(numpy.linalg.det(self.encrypt_key     )     )

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

					UpperCamelCase__ :int						=      len(self.key_string     )
					if greatest_common_divisor(lowerCamelCase__  ,     len(self.key_string     )     ) != 1:
						UpperCamelCase__ :int						=      (
						    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 				__a   ( self     :int  ,     lowerCamelCase__     :str     ):
					UpperCamelCase__ :str						=      [char for char in text.upper() if char in self.key_string]

					UpperCamelCase__ :int						=      chars[-1]
					while len(lowerCamelCase__     ) % self.break_key != 0:
						chars.append(lowerCamelCase__     )

					return "".join(lowerCamelCase__     )







				def 				__a   ( self     :Tuple  ,     lowerCamelCase__     :str     ):
					UpperCamelCase__ :Optional[int]						=      self.process_text(text.upper()     )
					UpperCamelCase__ :Optional[int]						=      """"""

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

					return encrypted







				def 				__a   ( self     :Optional[int]     ):
					UpperCamelCase__ :int						=      round(numpy.linalg.det(self.encrypt_key     )     )

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

					UpperCamelCase__ :Optional[int]						=      (
					    det_inv
					    * numpy.linalg.det(self.encrypt_key     )
					    * numpy.linalg.inv(self.encrypt_key     )
					)

					return self.to_int(self.modulus(lowerCamelCase__     )     )







				def 				__a   ( self     :Tuple  ,     lowerCamelCase__     :str     ):
					UpperCamelCase__ :List[str]						=      self.make_decrypt_key()
					UpperCamelCase__ :Dict						=      self.process_text(text.upper()     )
					UpperCamelCase__ :Any						=      """"""

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

					return decrypted




def 				A		(					)		-> None:
	UpperCamelCase__ :str						=      int(input("""Enter the order of the encryption key: """  )  )
	UpperCamelCase__ :List[Any]						=      []

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

	UpperCamelCase__ :Dict						=      HillCipher(numpy.array(lowercase__  )  )

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






from typing import TYPE_CHECKING

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


_lowercase		:  Dict			       ={
    """configuration_resnet""": ["""RESNET_PRETRAINED_CONFIG_ARCHIVE_MAP""", """ResNetConfig""", """ResNetOnnxConfig"""]
}

try:
		if not is_torch_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		_lowercase		:  Union[str, Any]			       =[
		    """RESNET_PRETRAINED_MODEL_ARCHIVE_LIST""",
		    """ResNetForImageClassification""",
		    """ResNetModel""",
		    """ResNetPreTrainedModel""",
		    """ResNetBackbone""",
		]

try:
		if not is_tf_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		_lowercase		:  Union[str, Any]			       =[
		    """TF_RESNET_PRETRAINED_MODEL_ARCHIVE_LIST""",
		    """TFResNetForImageClassification""",
		    """TFResNetModel""",
		    """TFResNetPreTrainedModel""",
		]

try:
		if not is_flax_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		_lowercase		:  Tuple			       =[
		    """FlaxResNetForImageClassification""",
		    """FlaxResNetModel""",
		    """FlaxResNetPreTrainedModel""",
		]

if TYPE_CHECKING:
		from .configuration_resnet import RESNET_PRETRAINED_CONFIG_ARCHIVE_MAP, ResNetConfig, ResNetOnnxConfig

		try:
				if not is_torch_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .modeling_resnet import (
				    RESNET_PRETRAINED_MODEL_ARCHIVE_LIST,
				    ResNetBackbone,
				    ResNetForImageClassification,
				    ResNetModel,
				    ResNetPreTrainedModel,
				)

		try:
				if not is_tf_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .modeling_tf_resnet import (
				    TF_RESNET_PRETRAINED_MODEL_ARCHIVE_LIST,
				    TFResNetForImageClassification,
				    TFResNetModel,
				    TFResNetPreTrainedModel,
				)

		try:
				if not is_flax_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .modeling_flax_resnet import FlaxResNetForImageClassification, FlaxResNetModel, FlaxResNetPreTrainedModel


else:
		import sys

		_lowercase		:  Union[str, Any]			       =_LazyModule(__name__, globals()["""__file__"""], _import_structure)
