





'''simple docstring'''




import string

import numpy



def 		__A		(  lowerCamelCase_			,			lowerCamelCase_	):


		"""simple docstring"""



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




class      UpperCamelCase__					:




					"""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 lowercase_			: x % 36			)

					SCREAMING_SNAKE_CASE__				=	numpy.vectorize(lowercase_			)


					def __init__(						self				:			Optional[Any]      ,						lowerCamelCase_				:			numpy.ndarray						):

							'''simple docstring'''



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


					def lowerCamelCase_			(						self				:			Any      ,						lowerCamelCase_				:			str						):

							'''simple docstring'''



							return self.key_string.index(__UpperCamelCase						)


					def lowerCamelCase_			(						self				:			Dict      ,						lowerCamelCase_				:			int						):

							'''simple docstring'''



							return self.key_string[round(__UpperCamelCase						)]


					def lowerCamelCase_			(						self				:			Optional[int]						):

							'''simple docstring'''



							SCREAMING_SNAKE_CASE :				str		=			round(numpy.linalg.det(self.encrypt_key						)						)

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

							SCREAMING_SNAKE_CASE :				List[str]		=			len(self.key_string						)
							if greatest_common_divisor(__UpperCamelCase      ,						len(self.key_string						)						) != 1:
									SCREAMING_SNAKE_CASE :				Tuple		=			(
									    f'''determinant modular {req_l} of encryption key({det}) '''
									    f'''is not co prime w.r.t {req_l}.\nTry another key.'''
									)
									raise ValueError(__UpperCamelCase						)


					def lowerCamelCase_			(						self				:			Optional[int]      ,						lowerCamelCase_				:			str						):

							'''simple docstring'''



							SCREAMING_SNAKE_CASE :				int		=			[char for char in text.upper() if char in self.key_string]

							SCREAMING_SNAKE_CASE :				Any		=			chars[-1]
							while len(__UpperCamelCase						) % self.break_key != 0:
									chars.append(__UpperCamelCase						)

							return "".join(__UpperCamelCase						)


					def lowerCamelCase_			(						self				:			Any      ,						lowerCamelCase_				:			str						):

							'''simple docstring'''



							SCREAMING_SNAKE_CASE :				Optional[int]		=			self.process_text(text.upper()						)
							SCREAMING_SNAKE_CASE :				Optional[int]		=			""""""

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

							return encrypted


					def lowerCamelCase_			(						self				:			Dict						):

							'''simple docstring'''



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

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

							SCREAMING_SNAKE_CASE :				Union[str, Any]		=			(
							    det_inv
							    * numpy.linalg.det(self.encrypt_key						)
							    * numpy.linalg.inv(self.encrypt_key						)
							)

							return self.to_int(self.modulus(__UpperCamelCase						)						)



					def lowerCamelCase_			(						self				:			List[Any]      ,						lowerCamelCase_				:			str						):

							'''simple docstring'''



							SCREAMING_SNAKE_CASE :				int		=			self.make_decrypt_key()
							SCREAMING_SNAKE_CASE :				Union[str, Any]		=			self.process_text(text.upper()						)
							SCREAMING_SNAKE_CASE :				Optional[Any]		=			""""""

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

							return decrypted







def 		__A		(  ):


		"""simple docstring"""



		SCREAMING_SNAKE_CASE :				List[str]		=			int(input("""Enter the order of the encryption key: """	)	)
		SCREAMING_SNAKE_CASE :				int		=			[]

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

		SCREAMING_SNAKE_CASE :				str		=			HillCipher(numpy.array(UpperCAmelCase__	)	)

		print("""Would you like to encrypt or decrypt some text? (1 or 2)"""	)
		SCREAMING_SNAKE_CASE :				Tuple		=			input("""\n1. Encrypt\n2. Decrypt\n"""	)
		if option == "1":
				SCREAMING_SNAKE_CASE :				Dict		=			input("""What text would you like to encrypt?: """	)
				print("""Your encrypted text is:"""	)
				print(hc.encrypt(UpperCAmelCase__	)	)
		elif option == "2":
				SCREAMING_SNAKE_CASE :				Optional[int]		=			input("""What text would you like to decrypt?: """	)
				print("""Your decrypted text is:"""	)
				print(hc.decrypt(UpperCAmelCase__	)	)


if __name__ == "__main__":
							import doctest

							doctest.testmod()

							main()





from typing import TYPE_CHECKING

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


lowercase   =	{
    '''configuration_blip''': [
        '''BLIP_PRETRAINED_CONFIG_ARCHIVE_MAP''',
        '''BlipConfig''',
        '''BlipTextConfig''',
        '''BlipVisionConfig''',
    ],
    '''processing_blip''': ['''BlipProcessor'''],
}

try:
		if not is_vision_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		lowercase   =	['''BlipImageProcessor''']


try:
		if not is_torch_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		lowercase   =	[
		    '''BLIP_PRETRAINED_MODEL_ARCHIVE_LIST''',
		    '''BlipModel''',
		    '''BlipPreTrainedModel''',
		    '''BlipForConditionalGeneration''',
		    '''BlipForQuestionAnswering''',
		    '''BlipVisionModel''',
		    '''BlipTextModel''',
		    '''BlipForImageTextRetrieval''',
		]

try:
		if not is_tf_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		lowercase   =	[
		    '''TF_BLIP_PRETRAINED_MODEL_ARCHIVE_LIST''',
		    '''TFBlipModel''',
		    '''TFBlipPreTrainedModel''',
		    '''TFBlipForConditionalGeneration''',
		    '''TFBlipForQuestionAnswering''',
		    '''TFBlipVisionModel''',
		    '''TFBlipTextModel''',
		    '''TFBlipForImageTextRetrieval''',
		]

if TYPE_CHECKING:
		from .configuration_blip import BLIP_PRETRAINED_CONFIG_ARCHIVE_MAP, BlipConfig, BlipTextConfig, BlipVisionConfig
		from .processing_blip import BlipProcessor

		try:
				if not is_vision_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .image_processing_blip import BlipImageProcessor

		try:
				if not is_torch_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .modeling_blip import (
				    BLIP_PRETRAINED_MODEL_ARCHIVE_LIST,
				    BlipForConditionalGeneration,
				    BlipForImageTextRetrieval,
				    BlipForQuestionAnswering,
				    BlipModel,
				    BlipPreTrainedModel,
				    BlipTextModel,
				    BlipVisionModel,
				)

		try:
				if not is_tf_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .modeling_tf_blip import (
				    TF_BLIP_PRETRAINED_MODEL_ARCHIVE_LIST,
				    TFBlipForConditionalGeneration,
				    TFBlipForImageTextRetrieval,
				    TFBlipForQuestionAnswering,
				    TFBlipModel,
				    TFBlipPreTrainedModel,
				    TFBlipTextModel,
				    TFBlipVisionModel,
				)

else:
		import sys

		lowercase   =	_LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)





