




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__					:							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)
				SCREAMING_SNAKE_CASE__					:							Dict	      =					numpy.vectorize(lambda __UpperCAmelCase: x % 36)

				SCREAMING_SNAKE_CASE__					:							Optional[int]	      =					numpy.vectorize(__UpperCAmelCase)


				def __init__(							self:   Tuple		,					_lowerCamelCase:   numpy.ndarray		):
											SCREAMING_SNAKE_CASE_   	=    self.modulus(_lowerCamelCase		)  # 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:   Optional[Any]		,					_lowerCamelCase:   str		):
											return self.key_string.index(_lowerCamelCase		)


				def     _A							(							self:   List[str]		,					_lowerCamelCase:   int		):
											return self.key_string[round(_lowerCamelCase		)]


				def     _A							(							self:   List[str]		):
											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(_lowerCamelCase		,					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(_lowerCamelCase		)


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

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

											return "".join(_lowerCamelCase		)


				def     _A							(							self:   Optional[int]		,					_lowerCamelCase:   str		):
											SCREAMING_SNAKE_CASE_   	=    self.process_text(text.upper()		)
											SCREAMING_SNAKE_CASE_   	=    ''''''

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

											return encrypted


				def     _A							(							self:   str		):
											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(_lowerCamelCase		)		)





				def     _A							(							self:   Union[str, Any]		,					_lowerCamelCase:   str		):
											SCREAMING_SNAKE_CASE_   	=    self.make_decrypt_key()
											SCREAMING_SNAKE_CASE_   	=    self.process_text(text.upper()		)
											SCREAMING_SNAKE_CASE_   	=    ''''''

											for i in range(0		,					len(_lowerCamelCase		) - self.break_key + 1		,					self.break_key		):
																		SCREAMING_SNAKE_CASE_   	=    text[i : i + self.break_key]
																		SCREAMING_SNAKE_CASE_   	=    [self.replace_letters(_lowerCamelCase		) for char in batch]
																		SCREAMING_SNAKE_CASE_   	=    numpy.array([vec]		).T
																		SCREAMING_SNAKE_CASE_   	=    self.modulus(decrypt_key.dot(_lowerCamelCase		)		).T.tolist()[0]
																		SCREAMING_SNAKE_CASE_   	=    ''''''.join(
																		    self.replace_digits(_lowerCamelCase		) 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 re
import string

import numpy as np

import datasets


__SCREAMING_SNAKE_CASE 						="""
Returns the rate at which the input predicted strings exactly match their references, ignoring any strings input as part of the regexes_to_ignore list.
"""

__SCREAMING_SNAKE_CASE 						="""
Args:
    predictions: List of predicted texts.
    references: List of reference texts.
    regexes_to_ignore: List, defaults to None. Regex expressions of characters to
        ignore when calculating the exact matches. Note: these regexes are removed
        from the input data before the changes based on the options below (e.g. ignore_case,
        ignore_punctuation, ignore_numbers) are applied.
    ignore_case: Boolean, defaults to False. If true, turns everything
        to lowercase so that capitalization differences are ignored.
    ignore_punctuation: Boolean, defaults to False. If true, removes all punctuation before
        comparing predictions and references.
    ignore_numbers: Boolean, defaults to False. If true, removes all punctuation before
        comparing predictions and references.
Returns:
    exact_match: Dictionary containing exact_match rate. Possible values are between 0.0 and 100.0, inclusive.
Examples:
    >>> exact_match = datasets.load_metric(\"exact_match\")
    >>> refs = [\"the cat\", \"theater\", \"YELLING\", \"agent007\"]
    >>> preds = [\"cat?\", \"theater\", \"yelling\", \"agent\"]
    >>> results = exact_match.compute(references=refs, predictions=preds)
    >>> print(round(results[\"exact_match\"], 1))
    25.0

    >>> exact_match = datasets.load_metric(\"exact_match\")
    >>> refs = [\"the cat\", \"theater\", \"YELLING\", \"agent007\"]
    >>> preds = [\"cat?\", \"theater\", \"yelling\", \"agent\"]
    >>> results = exact_match.compute(references=refs, predictions=preds, regexes_to_ignore=[\"the \", \"yell\"], ignore_case=True, ignore_punctuation=True)
    >>> print(round(results[\"exact_match\"], 1))
    50.0


    >>> exact_match = datasets.load_metric(\"exact_match\")
    >>> refs = [\"the cat\", \"theater\", \"YELLING\", \"agent007\"]
    >>> preds = [\"cat?\", \"theater\", \"yelling\", \"agent\"]
    >>> results = exact_match.compute(references=refs, predictions=preds, regexes_to_ignore=[\"the \", \"yell\", \"YELL\"], ignore_case=True, ignore_punctuation=True)
    >>> print(round(results[\"exact_match\"], 1))
    75.0

    >>> exact_match = datasets.load_metric(\"exact_match\")
    >>> refs = [\"the cat\", \"theater\", \"YELLING\", \"agent007\"]
    >>> preds = [\"cat?\", \"theater\", \"yelling\", \"agent\"]
    >>> results = exact_match.compute(references=refs, predictions=preds, regexes_to_ignore=[\"the \", \"yell\", \"YELL\"], ignore_case=True, ignore_punctuation=True, ignore_numbers=True)
    >>> print(round(results[\"exact_match\"], 1))
    100.0

    >>> exact_match = datasets.load_metric(\"exact_match\")
    >>> refs = [\"The cat sat on the mat.\", \"Theaters are great.\", \"It's like comparing oranges and apples.\"]
    >>> preds = [\"The cat sat on the mat?\", \"Theaters are great.\", \"It's like comparing apples and oranges.\"]
    >>> results = exact_match.compute(references=refs, predictions=preds)
    >>> print(round(results[\"exact_match\"], 1))
    33.3

"""

__SCREAMING_SNAKE_CASE 						="""
"""






@datasets.utils.file_utils.add_start_docstrings(_DESCRIPTION    ,  _KWARGS_DESCRIPTION)
class  __magic_name__						(  datasets.Metric):
				'''simple docstring'''







				def     _A							(							self:   Optional[int]		):
											return datasets.MetricInfo(
											    description=_DESCRIPTION		,					citation=_CITATION		,					inputs_description=_KWARGS_DESCRIPTION		,					features=datasets.Features(
											        {
											            '''predictions''': datasets.Value('''string'''		,					id='''sequence'''		),
											            '''references''': datasets.Value('''string'''		,					id='''sequence'''		),
											        }		)		,					reference_urls=[]		,					)





				def     _A							(							self:   Tuple		,					_lowerCamelCase:   int		,					_lowerCamelCase:   int		,					_lowerCamelCase:   Tuple=None		,					_lowerCamelCase:   str=False		,					_lowerCamelCase:   List[str]=False		,					_lowerCamelCase:   List[str]=False		,					):
											if regexes_to_ignore is not None:
																		for s in regexes_to_ignore:
																									SCREAMING_SNAKE_CASE_   	=    np.array([re.sub(_lowerCamelCase		,					''''''		,					_lowerCamelCase		) for x in predictions]		)
																									SCREAMING_SNAKE_CASE_   	=    np.array([re.sub(_lowerCamelCase		,					''''''		,					_lowerCamelCase		) for x in references]		)
											else:
																		SCREAMING_SNAKE_CASE_   	=    np.asarray(_lowerCamelCase		)
																		SCREAMING_SNAKE_CASE_   	=    np.asarray(_lowerCamelCase		)

											if ignore_case:
																		SCREAMING_SNAKE_CASE_   	=    np.char.lower(_lowerCamelCase		)
																		SCREAMING_SNAKE_CASE_   	=    np.char.lower(_lowerCamelCase		)

											if ignore_punctuation:
																		SCREAMING_SNAKE_CASE_   	=    string.punctuation.maketrans(''''''		,					''''''		,					string.punctuation		)
																		SCREAMING_SNAKE_CASE_   	=    np.char.translate(_lowerCamelCase		,					table=_lowerCamelCase		)
																		SCREAMING_SNAKE_CASE_   	=    np.char.translate(_lowerCamelCase		,					table=_lowerCamelCase		)

											if ignore_numbers:
																		SCREAMING_SNAKE_CASE_   	=    string.digits.maketrans(''''''		,					''''''		,					string.digits		)
																		SCREAMING_SNAKE_CASE_   	=    np.char.translate(_lowerCamelCase		,					table=_lowerCamelCase		)
																		SCREAMING_SNAKE_CASE_   	=    np.char.translate(_lowerCamelCase		,					table=_lowerCamelCase		)

											SCREAMING_SNAKE_CASE_   	=    predictions == references

											return {"exact_match": np.mean(_lowerCamelCase		) * 1_00}


