
import string

import numpy

def a__       (			A_,	A_   ):






  '''simple docstring'''





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




class 			UpperCAmelCase_     :


  '''simple docstring'''







  a__       			=						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__       			=						numpy.vectorize(lambda _A	: x % 36	)

  a__       			=						numpy.vectorize(_A	)
  def __init__(					self     :					Any     ,				UpperCamelCase__     :					numpy.ndarray       )     ->      None:







    """simple docstring"""






    __magic_name__								=			self.modulus(UpperCamelCase__       )  # mod36 calc's on the encrypt key
    self.check_determinant()  # validate the determinant of the encryption key
    __magic_name__								=			encrypt_key.shape[0]
  def 				_lowercase				(					self     :					Optional[int]     ,				UpperCamelCase__     :					str       )     ->      int:







    """simple docstring"""






    return self.key_string.index(UpperCamelCase__       )
  def 				_lowercase				(					self     :					List[str]     ,				UpperCamelCase__     :					int       )     ->      str:







    """simple docstring"""






    return self.key_string[round(UpperCamelCase__       )]
  def 				_lowercase				(					self     :					List[Any]       )     ->      None:







    """simple docstring"""






    __magic_name__								=			round(numpy.linalg.det(self.encrypt_key       )       )

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

    __magic_name__								=			len(self.key_string       )
    if greatest_common_divisor(UpperCamelCase__     ,				len(self.key_string       )       ) != 1:
      __magic_name__								=			(
          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 				_lowercase				(					self     :					Tuple     ,				UpperCamelCase__     :					str       )     ->      str:







    """simple docstring"""






    __magic_name__								=			[char for char in text.upper() if char in self.key_string]

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

    return "".join(UpperCamelCase__       )
  def 				_lowercase				(					self     :					Dict     ,				UpperCamelCase__     :					str       )     ->      str:







    """simple docstring"""






    __magic_name__								=			self.process_text(text.upper()       )
    __magic_name__								=			""""""

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

    return encrypted
  def 				_lowercase				(					self     :					Union[str, Any]       )     ->      numpy.ndarray:







    """simple docstring"""






    __magic_name__								=			round(numpy.linalg.det(self.encrypt_key       )       )

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

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

    return self.to_int(self.modulus(UpperCamelCase__       )       )





  def 				_lowercase				(					self     :					str     ,				UpperCamelCase__     :					str       )     ->      str:







    """simple docstring"""






    __magic_name__								=			self.make_decrypt_key()
    __magic_name__								=			self.process_text(text.upper()       )
    __magic_name__								=			""""""

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

    return decrypted







def a__       (			):






  '''simple docstring'''





  __magic_name__								=			int(input("""Enter the order of the encryption key: """   )   )
  __magic_name__								=			[]

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

  __magic_name__								=			HillCipher(numpy.array(A_   )   )

  print("""Would you like to encrypt or decrypt some text? (1 or 2)"""   )
  __magic_name__								=			input("""\n1. Encrypt\n2. Decrypt\n"""   )
  if option == "1":
    __magic_name__								=			input("""What text would you like to encrypt?: """   )
    print("""Your encrypted text is:"""   )
    print(hc.encrypt(A_   )   )
  elif option == "2":
    __magic_name__								=			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

# rely on isort to merge the imports
from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


__lowerCAmelCase     :	Union[str, Any]       			=  {
    'configuration_informer': [
        'INFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP',
        'InformerConfig',
    ],
}

try:
    if not is_torch_available():
        raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
    pass
else:
    __lowerCAmelCase     :	Optional[Any]       			=  [
        'INFORMER_PRETRAINED_MODEL_ARCHIVE_LIST',
        'InformerForPrediction',
        'InformerModel',
        'InformerPreTrainedModel',
    ]


if TYPE_CHECKING:
    from .configuration_informer import INFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP, InformerConfig

    try:
        if not is_torch_available():
            raise OptionalDependencyNotAvailable()
    except OptionalDependencyNotAvailable:
        pass
    else:
        from .modeling_informer import (
            INFORMER_PRETRAINED_MODEL_ARCHIVE_LIST,
            InformerForPrediction,
            InformerModel,
            InformerPreTrainedModel,
        )

else:
    import sys

    __lowerCAmelCase     :	List[str]       			=  _LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)

