





from __future__ import annotations


def 					A__	(       SCREAMING_SNAKE_CASE_		)   ->     List[Any]:
		lowerCamelCase   : Optional[int]								=str(UpperCAmelCase__		)
		return len(UpperCAmelCase__		) == 9 and set(UpperCAmelCase__		) == set('''123456789'''		)


def 					A__	(       )   ->     str:

		for base_num in range(9_9_9_9							,       4_9_9_9							,       -1		):
				lowerCamelCase   : str								=1_0_0_0_0_2 * base_num
				if is_9_pandigital(UpperCAmelCase__		):
						return candidate

		for base_num in range(3_3_3							,       9_9							,       -1		):
				lowerCamelCase   : List[Any]								=1_0_0_2_0_0_3 * base_num
				if is_9_pandigital(UpperCAmelCase__		):
						return candidate

		return None


if __name__ == "__main__":
				print(F"""{solution() = }""")








import string

import numpy


def 					A__	(       SCREAMING_SNAKE_CASE_							,       SCREAMING_SNAKE_CASE_		)   ->     int:
		return b if a == 0 else greatest_common_divisor(b % a							,       SCREAMING_SNAKE_CASE_		)
class        snake_case_		:
		lowerCamelCase    :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)
		lowerCamelCase    :str						=     numpy.vectorize(lambda _A: x % 36)

		lowerCamelCase    :str						=     numpy.vectorize(_A)







		def __init__(		self			,     __lowercase   )				->   None:
				lowerCamelCase   : Union[str, Any]								=self.modulus(__lowercase   )  # mod36 calc's on the encrypt key
				self.check_determinant()  # validate the determinant of the encryption key
				lowerCamelCase   : int								=encrypt_key.shape[0]







		def 			__lowercase   (		self			,     __lowercase   )				->   int:
				return self.key_string.index(__lowercase   )







		def 			__lowercase   (		self			,     __lowercase   )				->   str:
				return self.key_string[round(__lowercase   )]







		def 			__lowercase   (		self   )				->   None:
				lowerCamelCase   : Tuple								=round(numpy.linalg.det(self.encrypt_key   )   )

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

				lowerCamelCase   : Dict								=len(self.key_string   )
				if greatest_common_divisor(__lowercase			,     len(self.key_string   )   ) != 1:
						lowerCamelCase   : Union[str, 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:
				lowerCamelCase   : int								=[char for char in text.upper() if char in self.key_string]

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

				return "".join(__lowercase   )







		def 			__lowercase   (		self			,     __lowercase   )				->   str:
				lowerCamelCase   : str								=self.process_text(text.upper()   )
				lowerCamelCase   : Optional[int]								=''''''

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

				return encrypted







		def 			__lowercase   (		self   )				->   numpy.ndarray:
				lowerCamelCase   : List[Any]								=round(numpy.linalg.det(self.encrypt_key   )   )

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

				lowerCamelCase   : Union[str, 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:
				lowerCamelCase   : Optional[int]								=self.make_decrypt_key()
				lowerCamelCase   : int								=self.process_text(text.upper()   )
				lowerCamelCase   : Any								=''''''

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

				return decrypted


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

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

		lowerCamelCase   : Tuple								=HillCipher(numpy.array(SCREAMING_SNAKE_CASE_		)		)

		print('''Would you like to encrypt or decrypt some text? (1 or 2)'''		)
		lowerCamelCase   : Tuple								=input('''\n1. Encrypt\n2. Decrypt\n'''		)
		if option == "1":
				lowerCamelCase   : List[str]								=input('''What text would you like to encrypt?: '''		)
				print('''Your encrypted text is:'''		)
				print(hc.encrypt(SCREAMING_SNAKE_CASE_		)		)
		elif option == "2":
				lowerCamelCase   : int								=input('''What text would you like to decrypt?: '''		)
				print('''Your decrypted text is:'''		)
				print(hc.decrypt(SCREAMING_SNAKE_CASE_		)		)


if __name__ == "__main__":
				import doctest

				doctest.testmod()

				main()

