





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 typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


lowercase      :       List[Any]									=  {
    """configuration_nllb_moe""": [
        """NLLB_MOE_PRETRAINED_CONFIG_ARCHIVE_MAP""",
        """NllbMoeConfig""",
    ]
}

try:
    if not is_torch_available():
        raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
    pass
else:
    lowercase      :       Dict									=  [
        """NLLB_MOE_PRETRAINED_MODEL_ARCHIVE_LIST""",
        """NllbMoeForConditionalGeneration""",
        """NllbMoeModel""",
        """NllbMoePreTrainedModel""",
        """NllbMoeTop2Router""",
        """NllbMoeSparseMLP""",
    ]


if TYPE_CHECKING:
    from .configuration_nllb_moe import (
        NLLB_MOE_PRETRAINED_CONFIG_ARCHIVE_MAP,
        NllbMoeConfig,
    )

    try:
        if not is_torch_available():
            raise OptionalDependencyNotAvailable()
    except OptionalDependencyNotAvailable:
        pass
    else:
        from .modeling_nllb_moe import (
            NLLB_MOE_PRETRAINED_MODEL_ARCHIVE_LIST,
            NllbMoeForConditionalGeneration,
            NllbMoeModel,
            NllbMoePreTrainedModel,
            NllbMoeSparseMLP,
            NllbMoeTopaRouter,
        )


else:
    import sys

    lowercase      :       List[Any]									=  _LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)


