import string

import numpy






def        __UpperCAmelCase    (       UpperCAmelCase,		UpperCAmelCase       )->       int:



			"""simple docstring"""







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






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

						lowercase					 =     numpy.vectorize(_A    )

						def __init__(	self				:      int							,							__lowerCamelCase				:      numpy.ndarray   )							->		None:


									'''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        __a		(	self				:      Tuple							,							__lowerCamelCase				:      str   )							->		int:


									'''simple docstring'''

									return self.key_string.index(__lowerCamelCase   )

						def        __a		(	self				:      Tuple							,							__lowerCamelCase				:      int   )							->		str:


									'''simple docstring'''

									return self.key_string[round(__lowerCamelCase   )]

						def        __a		(	self				:      Optional[Any]   )							->		None:


									'''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        __a		(	self				:      List[Any]							,							__lowerCamelCase				:      str   )							->		str:


									'''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        __a		(	self				:      Optional[Any]							,							__lowerCamelCase				:      str   )							->		str:


									'''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        __a		(	self				:      Union[str, Any]   )							->		numpy.ndarray:


									'''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        __a		(	self				:      List[Any]							,							__lowerCamelCase				:      str   )							->		str:


									'''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        __UpperCAmelCase    (       )->       None:



			"""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(UpperCAmelCase       ):
						lowercase							=		[int(UpperCAmelCase       ) for x in input().split()]
						hill_matrix.append(UpperCAmelCase       )

			lowercase							=		HillCipher(numpy.array(UpperCAmelCase       )       )

			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(UpperCAmelCase       )       )
			elif option == "2":
						lowercase							=		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()






import cmath
import math






def        __UpperCAmelCase    (       UpperCAmelCase,		UpperCAmelCase,		UpperCAmelCase,		UpperCAmelCase       )->       complex:



			"""simple docstring"""







			lowercase							=		math.radians(UpperCAmelCase       )
			lowercase							=		math.radians(UpperCAmelCase       )

			# Convert voltage and current to rectangular form
			lowercase							=		cmath.rect(UpperCAmelCase,		UpperCAmelCase       )
			lowercase							=		cmath.rect(UpperCAmelCase,		UpperCAmelCase       )

			# Calculate apparent power
			return voltage_rect * current_rect


if __name__ == "__main__":
						import doctest

						doctest.testmod()





