






"""simple docstring"""

import string

import numpy

def 		__lowerCamelCase	(  __UpperCamelCase      ,       __UpperCamelCase       )						->    int:

		"""simple docstring"""







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


class 		__lowerCamelCase				:





		'''simple docstring'''






		a_	:				List[str]            =							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 A__			: x % 36			)

		a_	:				Optional[Any]            =							numpy.vectorize(A__			)





		def __init__(   self							:	Dict						,			a_							:	numpy.ndarray	):
				lowerCAmelCase_   :							Union[str, Any]									=			self.modulus(a_	)  # mod36 calc's on the encrypt key
				self.check_determinant()  # validate the determinant of the encryption key
				lowerCAmelCase_   :							Optional[Any]									=			encrypt_key.shape[0]





		def    lowerCamelCase       (   self							:	List[str]						,			a_							:	str	):
				return self.key_string.index(a_	)





		def    lowerCamelCase       (   self							:	int						,			a_							:	int	):
				return self.key_string[round(a_	)]





		def    lowerCamelCase       (   self							:	List[Any]	):
				lowerCAmelCase_   :							Optional[int]									=			round(numpy.linalg.det(self.encrypt_key	)	)

				if det < 0:
						lowerCAmelCase_   :							Optional[Any]									=			det % len(self.key_string	)

				lowerCAmelCase_   :							List[Any]									=			len(self.key_string	)
				if greatest_common_divisor(a_						,			len(self.key_string	)	) != 1:
						lowerCAmelCase_   :							List[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(a_	)





		def    lowerCamelCase       (   self							:	List[str]						,			a_							:	str	):
				lowerCAmelCase_   :							Any									=			[char for char in text.upper() if char in self.key_string]

				lowerCAmelCase_   :							Union[str, Any]									=			chars[-1]
				while len(a_	) % self.break_key != 0:
						chars.append(a_	)

				return "".join(a_	)





		def    lowerCamelCase       (   self							:	Dict						,			a_							:	str	):
				lowerCAmelCase_   :							Tuple									=			self.process_text(text.upper()	)
				lowerCAmelCase_   :							Any									=			""

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

				return encrypted





		def    lowerCamelCase       (   self							:	Optional[Any]	):
				lowerCAmelCase_   :							int									=			round(numpy.linalg.det(self.encrypt_key	)	)

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

				lowerCAmelCase_   :							Dict									=			(
				    det_inv
				    * numpy.linalg.det(self.encrypt_key	)
				    * numpy.linalg.inv(self.encrypt_key	)
				)

				return self.to_int(self.modulus(a_	)	)





		def    lowerCamelCase       (   self							:	Dict						,			a_							:	str	):
				lowerCAmelCase_   :							str									=			self.make_decrypt_key()
				lowerCAmelCase_   :							str									=			self.process_text(text.upper()	)
				lowerCAmelCase_   :							Union[str, Any]									=			""

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

				return decrypted







def 		__lowerCamelCase	(  )						->    None:

		"""simple docstring"""







		lowerCAmelCase_   :							List[str]									=			int(input("Enter the order of the encryption key: "       )       )
		lowerCAmelCase_   :							List[str]									=			[]

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

		lowerCAmelCase_   :							int									=			HillCipher(numpy.array(__UpperCamelCase       )       )

		print("Would you like to encrypt or decrypt some text? (1 or 2)"       )
		lowerCAmelCase_   :							Dict									=			input("\n1. Encrypt\n2. Decrypt\n"       )
		if option == "1":
				lowerCAmelCase_   :							List[Any]									=			input("What text would you like to encrypt?: "       )
				print("Your encrypted text is:"       )
				print(hc.encrypt(__UpperCamelCase       )       )
		elif option == "2":
				lowerCAmelCase_   :							List[Any]									=			input("What text would you like to decrypt?: "       )
				print("Your decrypted text is:"       )
				print(hc.decrypt(__UpperCamelCase       )       )


if __name__ == "__main__":
					import doctest

					doctest.testmod()

					main()








"""simple docstring"""

# coding=utf-8
# Copyright 2023 The HuggingFace Inc. team.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# this script dumps information about the environment

import os
import platform
import sys


lowercase__          = """3"""

print("""Python version:""", sys.version)

print("""OS platform:""", platform.platform())
print("""OS architecture:""", platform.machine())

try:
					import torch

					print("""Torch version:""", torch.__version__)
					print("""Cuda available:""", torch.cuda.is_available())
					print("""Cuda version:""", torch.version.cuda)
					print("""CuDNN version:""", torch.backends.cudnn.version())
					print("""Number of GPUs available:""", torch.cuda.device_count())
except ImportError:
					print("""Torch version:""", None)

try:
					import transformers

					print("""transformers version:""", transformers.__version__)
except ImportError:
					print("""transformers version:""", None)
