





import string

import numpy



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





class  A__    :




   """simple docstring"""



   __A   :				Union[str, Any]         =  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)
   __A   :				Tuple         =  numpy.vectorize(lambda __UpperCAmelCase	: x % 3_6	)

   __A   :				Optional[Any]         =  numpy.vectorize(__UpperCAmelCase	)

   def __init__(					self					,  lowercase)			->						None:







          '''simple docstring'''

          a__						:	int =				self.modulus(lowercase)  # mod36 calc's on the encrypt key
          self.check_determinant()  # validate the determinant of the encryption key
          a__						:	List[str] =				encrypt_key.shape[0]

   def 							__lowercase		(					self					,  lowercase)			->						int:







          '''simple docstring'''

          return self.key_string.index(lowercase)

   def 							__lowercase		(					self					,  lowercase)			->						str:







          '''simple docstring'''

          return self.key_string[round(lowercase)]

   def 							__lowercase		(					self)			->						None:







          '''simple docstring'''

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

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

          a__						:	str =				len(self.key_string)
          if greatest_common_divisor(lowercase					,  len(self.key_string)) != 1:
                 a__						:	Any =				(
                     F'determinant modular {req_l} of encryption key({det}) '
                     F'is not co prime w.r.t {req_l}.\nTry another key.'
                 )
                 raise ValueError(lowercase)

   def 							__lowercase		(					self					,  lowercase)			->						str:







          '''simple docstring'''

          a__						:	List[str] =				[char for char in text.upper() if char in self.key_string]

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

          return "".join(lowercase)

   def 							__lowercase		(					self					,  lowercase)			->						str:







          '''simple docstring'''

          a__						:	Optional[int] =				self.process_text(text.upper())
          a__						:	List[Any] =				''

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

          return encrypted

   def 							__lowercase		(					self)			->						numpy.ndarray:







          '''simple docstring'''

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

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

          a__						:	Any =				(
              det_inv
              * numpy.linalg.det(self.encrypt_key)
              * numpy.linalg.inv(self.encrypt_key)
          )

          return self.to_int(self.modulus(lowercase))

   def 							__lowercase		(					self					,  lowercase)			->						str:







          '''simple docstring'''

          a__						:	Optional[Any] =				self.make_decrypt_key()
          a__						:	Dict =				self.process_text(text.upper())
          a__						:	List[Any] =				''

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

          return decrypted



def A_	(		)  ->		None:
       a__						:	Optional[int] =				int(input('Enter the order of the encryption key: '				)				)
       a__						:	Optional[Any] =				[]

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

       a__						:	List[str] =				HillCipher(numpy.array(A__				)				)

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


if __name__ == "__main__":
    import doctest

    doctest.testmod()

    main()








from dataclasses import dataclass, field
from typing import Optional

from transformers import AutoConfig, AutoImageProcessor, AutoTokenizer, FlaxVisionEncoderDecoderModel, HfArgumentParser




@dataclass
class     snake_case__							:
				"""simple docstring"""



				SCREAMING_SNAKE_CASE_       :							str							 =					field(
				    metadata={"""help""": """The output directory where the model will be written."""}    ,       )
				SCREAMING_SNAKE_CASE_       :							str							 =					field(
				    metadata={
				        """help""": (
				            """The encoder model checkpoint for weights initialization."""
				            """Don't set if you want to train an encoder model from scratch."""
				        )
				    }    ,       )
				SCREAMING_SNAKE_CASE_       :							str							 =					field(
				    metadata={
				        """help""": (
				            """The decoder model checkpoint for weights initialization."""
				            """Don't set if you want to train a decoder model from scratch."""
				        )
				    }    ,       )
				SCREAMING_SNAKE_CASE_       :							Optional[str]							 =					field(
				    default=_UpperCamelCase    ,       metadata={"""help""": """Pretrained encoder config name or path if not the same as encoder_model_name"""}   )
				SCREAMING_SNAKE_CASE_       :							Optional[str]							 =					field(
				    default=_UpperCamelCase    ,       metadata={"""help""": """Pretrained decoder config name or path if not the same as decoder_model_name"""}   )




def 			__magic_name__				( ):






			'''simple docstring'''







			a    =			HfArgumentParser((ModelArguments,)   )
			((a)    ,		)    =			parser.parse_args_into_dataclasses()

			# Load pretrained model and tokenizer

			# Use explicit specified encoder config
			if model_args.encoder_config_name:
						a    =			AutoConfig.from_pretrained(model_args.encoder_config_name   )
			# Use pretrained encoder model's config
			else:
						a    =			AutoConfig.from_pretrained(model_args.encoder_model_name_or_path   )

			# Use explicit specified decoder config
			if model_args.decoder_config_name:
						a    =			AutoConfig.from_pretrained(model_args.decoder_config_name   )
			# Use pretrained decoder model's config
			else:
						a    =			AutoConfig.from_pretrained(model_args.decoder_model_name_or_path   )

			# necessary for `from_encoder_decoder_pretrained` when `decoder_config` is passed
			a    =			True
			a    =			True

			a    =			FlaxVisionEncoderDecoderModel.from_encoder_decoder_pretrained(
			    encoder_pretrained_model_name_or_path=model_args.encoder_model_name_or_path,  decoder_pretrained_model_name_or_path=model_args.decoder_model_name_or_path,  encoder_config=A,  decoder_config=A,  )

			# GPT2 only has bos/eos tokens but not decoder_start/pad tokens
			a    =			decoder_config.decoder_start_token_id
			a    =			decoder_config.pad_token_id
			if decoder_start_token_id is None:
						a    =			decoder_config.bos_token_id
			if pad_token_id is None:
						a    =			decoder_config.eos_token_id

			# This is necessary to make Flax's generate() work
			a    =			decoder_config.eos_token_id
			a    =			decoder_start_token_id
			a    =			pad_token_id

			a    =			AutoImageProcessor.from_pretrained(model_args.encoder_model_name_or_path   )

			a    =			AutoTokenizer.from_pretrained(model_args.decoder_model_name_or_path   )
			a    =			tokenizer.convert_ids_to_tokens(model.config.pad_token_id   )

			model.save_pretrained(model_args.output_dir   )
			image_processor.save_pretrained(model_args.output_dir   )
			tokenizer.save_pretrained(model_args.output_dir   )


if __name__ == "__main__":
		main()






