import string

import numpy


def        __lowerCAmelCase      (	_A			,_A       ):



							"""simple docstring"""


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


class _lowercase       :





							"""simple docstring"""




							lowerCAmelCase__							=       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)
							lowerCAmelCase__							=       numpy.vectorize(lambda _UpperCAmelCase    : x % 36    )

							lowerCAmelCase__							=       numpy.vectorize(__snake_case    )



							def __init__(     self  , UpperCAmelCase	):







														'''simple docstring'''






														_lowercase					=						self.modulus(__lowerCamelCase	)  # mod36 calc's on the encrypt key
														self.check_determinant()  # validate the determinant of the encryption key
														_lowercase					=						encrypt_key.shape[0]



							def      _UpperCAmelCase							(     self  , UpperCAmelCase	):







														'''simple docstring'''






														return self.key_string.index(__lowerCamelCase	)



							def      _UpperCAmelCase							(     self  , UpperCAmelCase	):







														'''simple docstring'''






														return self.key_string[round(__lowerCamelCase	)]



							def      _UpperCAmelCase							(     self	):







														'''simple docstring'''






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

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

														_lowercase					=						len(self.key_string	)
														if greatest_common_divisor(__lowerCamelCase  , len(self.key_string	)	) != 1:
																					_lowercase					=						(
																					    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  , UpperCAmelCase	):







														'''simple docstring'''






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

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

														return "".join(__lowerCamelCase	)



							def      _UpperCAmelCase							(     self  , UpperCAmelCase	):







														'''simple docstring'''






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

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

														return encrypted



							def      _UpperCAmelCase							(     self	):







														'''simple docstring'''






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

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

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

														return self.to_int(self.modulus(__lowerCamelCase	)	)



							def      _UpperCAmelCase							(     self  , UpperCAmelCase	):







														'''simple docstring'''






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

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

														return decrypted






def        __lowerCAmelCase      (	):



							"""simple docstring"""


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

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

							_lowercase					=						HillCipher(numpy.array(lowerCAmelCase_       )       )

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






from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


__a	 =      {
    """configuration_pegasus_x""": ["""PEGASUS_X_PRETRAINED_CONFIG_ARCHIVE_MAP""", """PegasusXConfig"""],
}

try:
 if not is_torch_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 __a	 =      [
     """PEGASUS_X_PRETRAINED_MODEL_ARCHIVE_LIST""",
     """PegasusXForConditionalGeneration""",
     """PegasusXModel""",
     """PegasusXPreTrainedModel""",
 ]


if TYPE_CHECKING:
 from .configuration_pegasus_x import PEGASUS_X_PRETRAINED_CONFIG_ARCHIVE_MAP, PegasusXConfig

 try:
  if not is_torch_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .modeling_pegasus_x import (
      PEGASUS_X_PRETRAINED_MODEL_ARCHIVE_LIST,
      PegasusXForConditionalGeneration,
      PegasusXModel,
      PegasusXPreTrainedModel,
  )


else:
 import sys

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



