



"""simple docstring"""


import string

import numpy







def  lowercase	(      _SCREAMING_SNAKE_CASE   :						int					,     _SCREAMING_SNAKE_CASE   :						int				):






				'''simple docstring'''



				return b if a == 0 else greatest_common_divisor(b % a					,     _SCREAMING_SNAKE_CASE				)
class 			_a :
			"""simple docstring"""
			UpperCamelCase__			      =	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)
			UpperCamelCase__			      =	numpy.vectorize(lambda lowerCAmelCase: x % 36)

			UpperCamelCase__			      =	numpy.vectorize(lowerCAmelCase)



			def __init__(		self     :    Optional[int]				,   __UpperCamelCase     :    numpy.ndarray   )->None:
							_UpperCAmelCase					=    self.modulus(__UpperCamelCase   )  # mod36 calc's on the encrypt key
							self.check_determinant()  # validate the determinant of the encryption key
							_UpperCAmelCase					=    encrypt_key.shape[0]



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



			def  lowercase__						(		self     :    List[Any]				,   __UpperCamelCase     :    int   )->str:
							return self.key_string[round(__UpperCamelCase   )]



			def  lowercase__						(		self     :    Optional[Any]   )->None:
							_UpperCAmelCase					=    round(numpy.linalg.det(self.encrypt_key   )   )

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

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

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

							return "".join(__UpperCamelCase   )



			def  lowercase__						(		self     :    List[Any]				,   __UpperCamelCase     :    str   )->str:
							_UpperCAmelCase					=    self.process_text(text.upper()   )
							_UpperCAmelCase					=    ''''''

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

							return encrypted



			def  lowercase__						(		self     :    Optional[Any]   )->numpy.ndarray:
							_UpperCAmelCase					=    round(numpy.linalg.det(self.encrypt_key   )   )

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

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

							return self.to_int(self.modulus(__UpperCamelCase   )   )



			def  lowercase__						(		self     :    List[Any]				,   __UpperCamelCase     :    str   )->str:
							_UpperCAmelCase					=    self.make_decrypt_key()
							_UpperCAmelCase					=    self.process_text(text.upper()   )
							_UpperCAmelCase					=    ''''''

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

							return decrypted







def  lowercase	(      ):






				'''simple docstring'''



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

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

				_UpperCAmelCase					=    HillCipher(numpy.array(_SCREAMING_SNAKE_CASE				)				)

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








"""simple docstring"""


import inspect
import os
import unittest

import torch

import accelerate
from accelerate import debug_launcher
from accelerate.test_utils import (
    execute_subprocess_async,
    require_cpu,
    require_huggingface_suite,
    require_multi_gpu,
    require_single_gpu,
)
from accelerate.utils import patch_environment
@require_huggingface_suite
class 			_a (					unittest.TestCase):
			"""simple docstring"""



			def  lowercase__						(		self     :    Tuple   )->int:
							_UpperCAmelCase					=    inspect.getfile(accelerate.test_utils   )
							_UpperCAmelCase					=    os.path.sep.join(
							    mod_file.split(os.path.sep   )[:-1] + ['''scripts''', '''external_deps''', '''test_metrics.py''']   )

							from accelerate.test_utils.scripts.external_deps import test_metrics  # noqa: F401

							_UpperCAmelCase					=    test_metrics



			@require_cpu
			def  lowercase__						(		self     :    Any   )->int:
							debug_launcher(self.test_metrics.main				,   num_processes=1   )



			@require_cpu
			def  lowercase__						(		self     :    List[str]   )->List[str]:
							debug_launcher(self.test_metrics.main   )



			@require_single_gpu
			def  lowercase__						(		self     :    List[Any]   )->Dict:
							self.test_metrics.main()



			@require_multi_gpu
			def  lowercase__						(		self     :    str   )->int:
							print(F'Found {torch.cuda.device_count()} devices.'   )
							_UpperCAmelCase					=    ['''torchrun''', F'--nproc_per_node={torch.cuda.device_count()}', self.test_file_path]
							with patch_environment(omp_num_threads=1   ):
											execute_subprocess_async(__UpperCamelCase				,   env=os.environ.copy()   )



