

'''simple docstring'''



import string

import numpy
def 						__lowerCamelCase	(       __snake_case					:		int,		__snake_case					:		int	)	->							int:






						"""simple docstring"""





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



class lowerCamelCase			:



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

			__snake_case        =	numpy.vectorize(lowercase_						)


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





									'''simple docstring'''
									A__					:       Any     =self.modulus(lowerCAmelCase_			)  # mod36 calc's on the encrypt key
									self.check_determinant()  # validate the determinant of the encryption key
									A__					:       List[Any]     =encrypt_key.shape[0]


			def lowercase__						(				self	:						Union[str, Any]		,      lowerCAmelCase_	:						str			)      ->		int:





									'''simple docstring'''
									return self.key_string.index(lowerCAmelCase_			)


			def lowercase__						(				self	:						Dict		,      lowerCAmelCase_	:						int			)      ->		str:





									'''simple docstring'''
									return self.key_string[round(lowerCAmelCase_			)]


			def lowercase__						(				self	:						Optional[int]			)      ->		None:





									'''simple docstring'''
									A__					:       int     =round(numpy.linalg.det(self.encrypt_key			)			)

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

									A__					:       Dict     =len(self.key_string			)
									if greatest_common_divisor(lowerCAmelCase_		,      len(self.key_string			)			) != 1:
															A__					:       Dict     =(
															    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 lowercase__						(				self	:						str		,      lowerCAmelCase_	:						str			)      ->		str:





									'''simple docstring'''
									A__					:       Union[str, Any]     =[char for char in text.upper() if char in self.key_string]

									A__					:       Optional[int]     =chars[-1]
									while len(lowerCAmelCase_			) % self.break_key != 0:
															chars.append(lowerCAmelCase_			)

									return "".join(lowerCAmelCase_			)


			def lowercase__						(				self	:						Union[str, Any]		,      lowerCAmelCase_	:						str			)      ->		str:





									'''simple docstring'''
									A__					:       str     =self.process_text(text.upper()			)
									A__					:       Any     =""""""

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

									return encrypted


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





									'''simple docstring'''
									A__					:       Optional[int]     =round(numpy.linalg.det(self.encrypt_key			)			)

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

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

									return self.to_int(self.modulus(lowerCAmelCase_			)			)



			def lowercase__						(				self	:						Optional[int]		,      lowerCAmelCase_	:						str			)      ->		str:





									'''simple docstring'''
									A__					:       str     =self.make_decrypt_key()
									A__					:       List[Any]     =self.process_text(text.upper()			)
									A__					:       Tuple     =""""""

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

									return decrypted


def 						__lowerCamelCase	(       )	->							None:






						"""simple docstring"""





						A__					:       Tuple     =int(input("""Enter the order of the encryption key: """	)	)
						A__					:       Dict     =[]

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

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

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



import warnings
from typing import List, Optional, Union

from ...image_utils import ImageInput
from ...processing_utils import ProcessorMixin
from ...tokenization_utils_base import BatchEncoding, PaddingStrategy, PreTokenizedInput, TextInput, TruncationStrategy
from ...utils import TensorType



class lowerCamelCase			(  lowercase_						):



			'''simple docstring'''






			__snake_case        =	['image_processor', 'tokenizer']
			__snake_case        =	'FlavaImageProcessor'
			__snake_case        =	('BertTokenizer', 'BertTokenizerFast')


			def __init__(				self	:						Optional[int]		,      lowerCAmelCase_	:						List[str]=None		,      lowerCAmelCase_	:						Optional[Any]=None		,      **lowerCAmelCase_	:						Optional[Any]			)      ->		List[str]:





									'''simple docstring'''
									A__					:       Any     =None
									if "feature_extractor" in kwargs:
															warnings.warn(
															    """The `feature_extractor` argument is deprecated and will be removed in v5, use `image_processor`"""
															    """ instead."""		,      lowerCAmelCase_		,      )
															A__					:       Optional[Any]     =kwargs.pop("""feature_extractor"""			)

									A__					:       List[Any]     =image_processor if image_processor is not None else feature_extractor
									if image_processor is None:
															raise ValueError("""You need to specify an `image_processor`."""			)
									if tokenizer is None:
															raise ValueError("""You need to specify a `tokenizer`."""			)

									super().__init__(lowerCAmelCase_		,      lowerCAmelCase_			)
									A__					:       int     =self.image_processor


			def __call__(				self	:						Union[str, Any]		,      lowerCAmelCase_	:						Optional[ImageInput] = None		,      lowerCAmelCase_	:						Optional[Union[TextInput, PreTokenizedInput, List[TextInput], List[PreTokenizedInput]]] = None		,      lowerCAmelCase_	:						bool = True		,      lowerCAmelCase_	:						Union[bool, str, PaddingStrategy] = False		,      lowerCAmelCase_	:						Union[bool, str, TruncationStrategy] = False		,      lowerCAmelCase_	:						Optional[int] = None		,      lowerCAmelCase_	:						int = 0		,      lowerCAmelCase_	:						Optional[int] = None		,      lowerCAmelCase_	:						Optional[bool] = None		,      lowerCAmelCase_	:						Optional[bool] = None		,      lowerCAmelCase_	:						Optional[bool] = None		,      lowerCAmelCase_	:						Optional[bool] = None		,      lowerCAmelCase_	:						bool = False		,      lowerCAmelCase_	:						bool = False		,      lowerCAmelCase_	:						bool = False		,      lowerCAmelCase_	:						bool = False		,      lowerCAmelCase_	:						bool = True		,      lowerCAmelCase_	:						Optional[Union[str, TensorType]] = None		,      **lowerCAmelCase_	:						Optional[int]		,      )      ->		str:





									'''simple docstring'''

									if text is None and images is None:
															raise ValueError("""You have to specify either text or images. Both cannot be none."""			)

									if text is not None:
															A__					:       int     =self.tokenizer(
															    text=lowerCAmelCase_		,      add_special_tokens=lowerCAmelCase_		,      padding=lowerCAmelCase_		,      truncation=lowerCAmelCase_		,      max_length=lowerCAmelCase_		,      stride=lowerCAmelCase_		,      pad_to_multiple_of=lowerCAmelCase_		,      return_token_type_ids=lowerCAmelCase_		,      return_attention_mask=lowerCAmelCase_		,      return_overflowing_tokens=lowerCAmelCase_		,      return_special_tokens_mask=lowerCAmelCase_		,      return_offsets_mapping=lowerCAmelCase_		,      return_length=lowerCAmelCase_		,      verbose=lowerCAmelCase_		,      return_tensors=lowerCAmelCase_		,      **lowerCAmelCase_		,      )
									if images is not None:
															A__					:       List[str]     =self.image_processor(
															    lowerCAmelCase_		,      return_image_mask=lowerCAmelCase_		,      return_codebook_pixels=lowerCAmelCase_		,      return_tensors=lowerCAmelCase_		,      **lowerCAmelCase_		,      )

									if text is not None and images is not None:
															encoding.update(lowerCAmelCase_			)
															return encoding
									elif text is not None:
															return encoding
									else:
															return BatchEncoding(data=dict(**lowerCAmelCase_			)		,      tensor_type=lowerCAmelCase_			)


			def lowercase__						(				self	:						Any		,      *lowerCAmelCase_	:						str		,      **lowerCAmelCase_	:						Optional[int]			)      ->		str:





									'''simple docstring'''
									return self.tokenizer.batch_decode(*lowerCAmelCase_		,      **lowerCAmelCase_			)


			def lowercase__						(				self	:						List[Any]		,      *lowerCAmelCase_	:						List[Any]		,      **lowerCAmelCase_	:						Any			)      ->		Tuple:





									'''simple docstring'''
									return self.tokenizer.decode(*lowerCAmelCase_		,      **lowerCAmelCase_			)


			@property
			def lowercase__						(				self	:						Tuple			)      ->		Tuple:





									'''simple docstring'''
									A__					:       Any     =self.tokenizer.model_input_names
									A__					:       Optional[Any]     =self.image_processor.model_input_names
									return list(dict.fromkeys(tokenizer_input_names + image_processor_input_names			)			)


			@property
			def lowercase__						(				self	:						Tuple			)      ->		int:





									'''simple docstring'''
									warnings.warn(
									    """`feature_extractor_class` is deprecated and will be removed in v5. Use `image_processor_class` instead."""		,      lowerCAmelCase_		,      )
									return self.image_processor_class



			@property
			def lowercase__						(				self	:						Tuple			)      ->		Dict:





									'''simple docstring'''
									warnings.warn(
									    """`feature_extractor` is deprecated and will be removed in v5. Use `image_processor` instead."""		,      lowerCAmelCase_		,      )
									return self.image_processor

