




import string

import numpy

def 			a   (_lowerCAmelCase  ,    _lowerCAmelCase     ):
							return b if a == 0 else greatest_common_divisor(b % a  ,    _lowerCAmelCase     )






class  __magic_name__						:
				'''simple docstring'''







				SCREAMING_SNAKE_CASE__					:							Union[str, Any]	      =					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)
				SCREAMING_SNAKE_CASE__					:							Optional[Any]	      =					numpy.vectorize(lambda __UpperCAmelCase: x % 36)

				SCREAMING_SNAKE_CASE__					:							Dict	      =					numpy.vectorize(SCREAMING_SNAKE_CASE__)


				def __init__(							self:   Tuple		,					_lowerCamelCase:   Tuple		):
											SCREAMING_SNAKE_CASE_   	=    self.modulus(snake_case__		)  # mod36 calc's on the encrypt key
											self.check_determinant()  # validate the determinant of the encryption key
											SCREAMING_SNAKE_CASE_   	=    encrypt_key.shape[0]


				def     _A							(							self:   Any		,					_lowerCamelCase:   Dict		):
											return self.key_string.index(snake_case__		)


				def     _A							(							self:   Any		,					_lowerCamelCase:   Union[str, Any]		):
											return self.key_string[round(snake_case__		)]


				def     _A							(							self:   Any		):
											SCREAMING_SNAKE_CASE_   	=    round(numpy.linalg.det(self.encrypt_key		)		)

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

											SCREAMING_SNAKE_CASE_   	=    len(self.key_string		)
											if greatest_common_divisor(snake_case__		,					len(self.key_string		)		) != 1:
																		SCREAMING_SNAKE_CASE_   	=    (
																		    f"determinant modular {req_l} of encryption key({det}) "
																		    f"is not co prime w.r.t {req_l}.\nTry another key."
																		)
																		raise ValueError(snake_case__		)


				def     _A							(							self:   Optional[Any]		,					_lowerCamelCase:   str		):
											SCREAMING_SNAKE_CASE_   	=    [char for char in text.upper() if char in self.key_string]

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

											return "".join(snake_case__		)


				def     _A							(							self:   Tuple		,					_lowerCamelCase:   Dict		):
											SCREAMING_SNAKE_CASE_   	=    self.process_text(text.upper()		)
											SCREAMING_SNAKE_CASE_   	=    ""

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

											return encrypted


				def     _A							(							self:   Dict		):
											SCREAMING_SNAKE_CASE_   	=    round(numpy.linalg.det(self.encrypt_key		)		)

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

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

											return self.to_int(self.modulus(snake_case__		)		)





				def     _A							(							self:   Optional[Any]		,					_lowerCamelCase:   int		):
											SCREAMING_SNAKE_CASE_   	=    self.make_decrypt_key()
											SCREAMING_SNAKE_CASE_   	=    self.process_text(text.upper()		)
											SCREAMING_SNAKE_CASE_   	=    ""

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

											return decrypted






def 			a   ():
							SCREAMING_SNAKE_CASE_   	=    int(input('''Enter the order of the encryption key: '''     )     )
							SCREAMING_SNAKE_CASE_   	=    []

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

							SCREAMING_SNAKE_CASE_   	=    HillCipher(numpy.array(_lowerCAmelCase     )     )

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








import unittest

from transformers import is_torch_available
from transformers.testing_utils import require_torch


if is_torch_available():
			import torch

			from transformers.generation import DisjunctiveConstraint






@require_torch
class  __magic_name__						(  unittest.TestCase):
				'''simple docstring'''







				def     _A							(							self:   str		):
											# For consistency across different places the DisjunctiveConstraint is called,
											# dc.token_ids is a list of integers. It is also initialized only by integers.

											SCREAMING_SNAKE_CASE_   	=    [[1, 2, 4], [1, 2, 3, 4]]
											SCREAMING_SNAKE_CASE_   	=    DisjunctiveConstraint(_lowerCamelCase		)
											self.assertTrue(isinstance(dc.token_ids		,					_lowerCamelCase		)		)

											with self.assertRaises(_lowerCamelCase		):
																		DisjunctiveConstraint(torch.LongTensor([[1, 2, 4], [1, 2, 3]]		)		)

											with self.assertRaises(_lowerCamelCase		):
																		DisjunctiveConstraint([torch.LongTensor([1, 2, 4]		), torch.LongTensor([1, 2, 3, 4, 5]		)]		)


				def     _A							(							self:   Union[str, Any]		):
											# We can't have constraints that are complete subsets of another. This leads to a preverse
											# interpretation of "constraint fulfillment": does generating [1,2,3] fulfill the constraint?
											# It would mean that it generated [1,2] which fulfills it, but it's in the middle of potentially
											# fulfilling [1,2,3,4]. If we believe that [1,2,3] does fulfill the constraint, then the algorithm
											# will necessarily never reach [1,2,3,4], giving users a false sense of control (better to just not allow it).
											SCREAMING_SNAKE_CASE_   	=    [[1, 2], [1, 2, 3, 4]]

											with self.assertRaises(_lowerCamelCase		):
																		DisjunctiveConstraint(_lowerCamelCase		)  # fails here


				def     _A							(							self:   Dict		):
											SCREAMING_SNAKE_CASE_   	=    [[1, 2, 3], [1, 2, 4]]

											SCREAMING_SNAKE_CASE_   	=    DisjunctiveConstraint(_lowerCamelCase		)

											SCREAMING_SNAKE_CASE_	,	SCREAMING_SNAKE_CASE_	,	SCREAMING_SNAKE_CASE_   	=    dc.update(1		)
											SCREAMING_SNAKE_CASE_   	=    stepped is True and completed is False and reset is False
											self.assertTrue(_lowerCamelCase		)
											self.assertTrue(not dc.completed		)
											self.assertTrue(dc.current_seq == [1]		)

											SCREAMING_SNAKE_CASE_	,	SCREAMING_SNAKE_CASE_	,	SCREAMING_SNAKE_CASE_   	=    dc.update(2		)
											SCREAMING_SNAKE_CASE_   	=    stepped is True and completed is False and reset is False
											self.assertTrue(_lowerCamelCase		)
											self.assertTrue(not dc.completed		)
											self.assertTrue(dc.current_seq == [1, 2]		)

											SCREAMING_SNAKE_CASE_	,	SCREAMING_SNAKE_CASE_	,	SCREAMING_SNAKE_CASE_   	=    dc.update(3		)
											SCREAMING_SNAKE_CASE_   	=    stepped is True and completed is True and reset is False
											self.assertTrue(_lowerCamelCase		)
											self.assertTrue(dc.completed		)  # Completed!
											self.assertTrue(dc.current_seq == [1, 2, 3]		)





				def     _A							(							self:   Optional[int]		):
											SCREAMING_SNAKE_CASE_   	=    [[1, 2, 3], [1, 2, 4, 5], [1, 2, 5]]

											SCREAMING_SNAKE_CASE_   	=    DisjunctiveConstraint(_lowerCamelCase		)

											SCREAMING_SNAKE_CASE_	,	SCREAMING_SNAKE_CASE_	,	SCREAMING_SNAKE_CASE_   	=    dc.update(1		)
											self.assertTrue(not dc.completed		)
											self.assertTrue(dc.current_seq == [1]		)

											SCREAMING_SNAKE_CASE_	,	SCREAMING_SNAKE_CASE_	,	SCREAMING_SNAKE_CASE_   	=    dc.update(2		)
											self.assertTrue(not dc.completed		)
											self.assertTrue(dc.current_seq == [1, 2]		)

											SCREAMING_SNAKE_CASE_	,	SCREAMING_SNAKE_CASE_	,	SCREAMING_SNAKE_CASE_   	=    dc.update(4		)
											self.assertTrue(not dc.completed		)
											self.assertTrue(dc.current_seq == [1, 2, 4]		)

											SCREAMING_SNAKE_CASE_	,	SCREAMING_SNAKE_CASE_	,	SCREAMING_SNAKE_CASE_   	=    dc.update(5		)
											self.assertTrue(dc.completed		)  # Completed!
											self.assertTrue(dc.current_seq == [1, 2, 4, 5]		)

											dc.reset()

											SCREAMING_SNAKE_CASE_	,	SCREAMING_SNAKE_CASE_	,	SCREAMING_SNAKE_CASE_   	=    dc.update(1		)
											self.assertTrue(not dc.completed		)
											self.assertTrue(dc.remaining() == 3		)
											self.assertTrue(dc.current_seq == [1]		)

											SCREAMING_SNAKE_CASE_	,	SCREAMING_SNAKE_CASE_	,	SCREAMING_SNAKE_CASE_   	=    dc.update(2		)
											self.assertTrue(not dc.completed		)
											self.assertTrue(dc.remaining() == 2		)
											self.assertTrue(dc.current_seq == [1, 2]		)

											SCREAMING_SNAKE_CASE_	,	SCREAMING_SNAKE_CASE_	,	SCREAMING_SNAKE_CASE_   	=    dc.update(5		)
											self.assertTrue(dc.completed		)  # Completed!
											self.assertTrue(dc.remaining() == 0		)
											self.assertTrue(dc.current_seq == [1, 2, 5]		)


