


import string

import numpy



def   snake_case						(				_a:     Dict		,   _a:     Dict							)->		Dict:
      '''simple docstring'''


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



class   _a      :
    a_    :				Tuple             =    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_    :				Dict             =    numpy.vectorize(lambda SCREAMING_SNAKE_CASE_ : x % 36 )

    a_    :				Optional[int]             =    numpy.vectorize(__UpperCAmelCase )
    def __init__( self							:					Tuple							,					SCREAMING_SNAKE_CASE__							:					numpy.ndarray				):
          lowerCamelCase__           =		self.modulus(_lowerCamelCase				)  # mod36 calc's on the encrypt key
          self.check_determinant()  # validate the determinant of the encryption key
          lowerCamelCase__           =		encrypt_key.shape[0]
    def      _UpperCamelCase       ( self							:					Optional[Any]							,					SCREAMING_SNAKE_CASE__							:					str				):
          return self.key_string.index(_lowerCamelCase				)
    def      _UpperCamelCase       ( self							:					List[str]							,					SCREAMING_SNAKE_CASE__							:					int				):
          return self.key_string[round(_lowerCamelCase				)]
    def      _UpperCamelCase       ( self							:					List[str]				):
          lowerCamelCase__           =		round(numpy.linalg.det(self.encrypt_key				)				)

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

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

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

          return "".join(_lowerCamelCase				)
    def      _UpperCamelCase       ( self							:					Optional[int]							,					SCREAMING_SNAKE_CASE__							:					str				):
          lowerCamelCase__           =		self.process_text(text.upper()				)
          lowerCamelCase__           =		''

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

          return encrypted
    def      _UpperCamelCase       ( self							:					str				):
          lowerCamelCase__           =		round(numpy.linalg.det(self.encrypt_key				)				)

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

          lowerCamelCase__           =		(
              det_inv
              * numpy.linalg.det(self.encrypt_key				)
              * numpy.linalg.inv(self.encrypt_key				)
          )

          return self.to_int(self.modulus(_lowerCamelCase				)				)


    def      _UpperCamelCase       ( self							:					Union[str, Any]							,					SCREAMING_SNAKE_CASE__							:					str				):
          lowerCamelCase__           =		self.make_decrypt_key()
          lowerCamelCase__           =		self.process_text(text.upper()				)
          lowerCamelCase__           =		''

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

          return decrypted





def   snake_case						(				)->		Union[str, Any]:
      '''simple docstring'''


      lowerCamelCase__           =		int(input('Enter the order of the encryption key: '							)							)
      lowerCamelCase__           =		[]

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

      lowerCamelCase__           =		HillCipher(numpy.array(_lowerCAmelCase							)							)

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


if __name__ == "__main__":
   import doctest

   doctest.testmod()

   main()







"""simple docstring"""


from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_tokenizers_available, is_torch_available


_snake_case          =							{
    "configuration_m2m_100": ["M2M_100_PRETRAINED_CONFIG_ARCHIVE_MAP", "M2M100Config", "M2M100OnnxConfig"],
    "tokenization_m2m_100": ["M2M100Tokenizer"],
}


try:
   if not is_torch_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   _snake_case          =							[
       "M2M_100_PRETRAINED_MODEL_ARCHIVE_LIST",
       "M2M100ForConditionalGeneration",
       "M2M100Model",
       "M2M100PreTrainedModel",
   ]


if TYPE_CHECKING:
   from .configuration_mam_aaa import M2M_100_PRETRAINED_CONFIG_ARCHIVE_MAP, MaMaaaConfig, MaMaaaOnnxConfig
   from .tokenization_mam_aaa import MaMaaaTokenizer

   try:
      if not is_torch_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .modeling_mam_aaa import (
          M2M_100_PRETRAINED_MODEL_ARCHIVE_LIST,
          MaMaaaForConditionalGeneration,
          MaMaaaModel,
          MaMaaaPreTrainedModel,
      )


else:
   import sys

   _snake_case          =							_LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)



