





import string

import numpy



def        __lowercase       (				_SCREAMING_SNAKE_CASE			,						_SCREAMING_SNAKE_CASE     )			->       int:


						'''simple docstring'''


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

class 		UpperCamelCase__			:



					'''simple docstring'''

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

					__snake_case   :     Tuple		     =      numpy.vectorize(lowerCamelCase__       )






					def __init__(							self						:   List[Any]						,lowerCamelCase__						:   numpy.ndarray	)					->		str:




											'''simple docstring'''


											SCREAMING_SNAKE_CASE		=						self.modulus(__A	)  # 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     SCREAMING_SNAKE_CASE__  (							self						:   Union[str, Any]						,lowerCamelCase__						:   str	)					->		Union[str, Any]:




											'''simple docstring'''


											return self.key_string.index(__A	)






					def     SCREAMING_SNAKE_CASE__  (							self						:   Dict						,lowerCamelCase__						:   int	)					->		Optional[int]:




											'''simple docstring'''


											return self.key_string[round(__A	)]






					def     SCREAMING_SNAKE_CASE__  (							self						:   str	)					->		Tuple:




											'''simple docstring'''


											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(__A						,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(__A	)






					def     SCREAMING_SNAKE_CASE__  (							self						:   Union[str, Any]						,lowerCamelCase__						:   str	)					->		Union[str, Any]:




											'''simple docstring'''


											SCREAMING_SNAKE_CASE		=						[char for char in text.upper() if char in self.key_string]

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

											return "".join(__A	)






					def     SCREAMING_SNAKE_CASE__  (							self						:   Any						,lowerCamelCase__						:   str	)					->		Optional[int]:




											'''simple docstring'''


											SCREAMING_SNAKE_CASE		=						self.process_text(text.upper()	)
											SCREAMING_SNAKE_CASE		=						''''''

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

											return encrypted






					def     SCREAMING_SNAKE_CASE__  (							self						:   List[Any]	)					->		Optional[int]:




											'''simple docstring'''


											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(__A	)	)






					def     SCREAMING_SNAKE_CASE__  (							self						:   List[Any]						,lowerCamelCase__						:   str	)					->		Tuple:




											'''simple docstring'''


											SCREAMING_SNAKE_CASE		=						self.make_decrypt_key()
											SCREAMING_SNAKE_CASE		=						self.process_text(text.upper()	)
											SCREAMING_SNAKE_CASE		=						''''''

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

											return decrypted



def        __lowercase       (				)			->       None:


						'''simple docstring'''


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

						SCREAMING_SNAKE_CASE		=						HillCipher(numpy.array(_SCREAMING_SNAKE_CASE     )     )

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









import json
import sys



def        __lowercase       (				_SCREAMING_SNAKE_CASE			,						_SCREAMING_SNAKE_CASE     )			->       Any:


      '''simple docstring'''


      with open(_SCREAMING_SNAKE_CASE			,						encoding="""utf-8"""     ) as f:
            SCREAMING_SNAKE_CASE		=						json.load(_SCREAMING_SNAKE_CASE     )

      SCREAMING_SNAKE_CASE		=						["""<details>""", """<summary>Show updated benchmarks!</summary>""", """ """]

      for benchmark_name in sorted(_SCREAMING_SNAKE_CASE     ):
            SCREAMING_SNAKE_CASE		=						results[benchmark_name]

            SCREAMING_SNAKE_CASE		=						benchmark_name.split("""/"""     )[-1]
            output_md.append(F"""### Benchmark: {benchmark_file_name}"""     )

            SCREAMING_SNAKE_CASE		=						"""| metric |"""
            SCREAMING_SNAKE_CASE		=						"""|--------|"""
            SCREAMING_SNAKE_CASE		=						"""| new / old (diff) |"""
            for metric_name in sorted(_SCREAMING_SNAKE_CASE     ):
                  SCREAMING_SNAKE_CASE		=						benchmark_res[metric_name]
                  SCREAMING_SNAKE_CASE		=						metric_vals["""new"""]
                  SCREAMING_SNAKE_CASE		=						metric_vals.get("""old"""			,						_SCREAMING_SNAKE_CASE     )
                  SCREAMING_SNAKE_CASE		=						metric_vals.get("""diff"""			,						_SCREAMING_SNAKE_CASE     )

                  SCREAMING_SNAKE_CASE		=						F""" {new_val:f}""" if isinstance(_SCREAMING_SNAKE_CASE			,						(int, float)     ) else """None"""

                  if old_val is not None:
                        val_str += F""" / {old_val:f}""" if isinstance(_SCREAMING_SNAKE_CASE			,						(int, float)     ) else "None"
                  if dif_val is not None:
                        val_str += F""" ({dif_val:f})""" if isinstance(_SCREAMING_SNAKE_CASE			,						(int, float)     ) else "None"

                  title += " " + metric_name + " |"
                  lines += "---|"
                  value += val_str + " |"

            output_md += [title, lines, value, " "]

      output_md.append("""</details>"""     )

      with open(_SCREAMING_SNAKE_CASE			,						"""w"""			,						encoding="""utf-8"""     ) as f:
            f.writelines("""\n""".join(_SCREAMING_SNAKE_CASE     )     )


if __name__ == "__main__":
      SCREAMING_SNAKE_CASE_						       =	sys.argv[1]
      SCREAMING_SNAKE_CASE_						       =	sys.argv[2]

      format_json_to_md(input_json_file, output_md_file)


