





import string

import numpy




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







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   ,				a__):



             """simple docstring"""





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


      def 					__snake_case      (		self   ,				a__):



             """simple docstring"""





             return self.key_string.index(a__)


      def 					__snake_case      (		self   ,				a__):



             """simple docstring"""





             return self.key_string[round(a__)]


      def 					__snake_case      (		self):



             """simple docstring"""





             _lowerCamelCase				:  Tuple						=		round(numpy.linalg.det(self.encrypt_key))

             if det < 0:
                    _lowerCamelCase				:  Union[str, Any]						=		det % len(self.key_string)

             _lowerCamelCase				:  int						=		len(self.key_string)
             if greatest_common_divisor(a__   ,				len(self.key_string)) != 1:
                    _lowerCamelCase				:  int						=		(
                        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 					__snake_case      (		self   ,				a__):



             """simple docstring"""





             _lowerCamelCase				:  Optional[int]						=		[char for char in text.upper() if char in self.key_string]

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

             return "".join(a__)


      def 					__snake_case      (		self   ,				a__):



             """simple docstring"""





             _lowerCamelCase				:  List[Any]						=		self.process_text(text.upper())
             _lowerCamelCase				:  int						=		''''''

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

             return encrypted


      def 					__snake_case      (		self):



             """simple docstring"""





             _lowerCamelCase				:  Optional[Any]						=		round(numpy.linalg.det(self.encrypt_key))

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

             _lowerCamelCase				:  Tuple						=		(
                 det_inv
                 * numpy.linalg.det(self.encrypt_key)
                 * numpy.linalg.inv(self.encrypt_key)
             )

             return self.to_int(self.modulus(a__))



      def 					__snake_case      (		self   ,				a__):



             """simple docstring"""





             _lowerCamelCase				:  Optional[Any]						=		self.make_decrypt_key()
             _lowerCamelCase				:  Optional[int]						=		self.process_text(text.upper())
             _lowerCamelCase				:  Optional[Any]						=		''''''

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

             return decrypted




def  __UpperCAmelCase(   ):
       _lowerCamelCase				:  List[Any]						=		int(input('''Enter the order of the encryption key: '''   )   )
       _lowerCamelCase				:  Any						=		[]

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

       _lowerCamelCase				:  Optional[int]						=		HillCipher(numpy.array(lowercase_   )   )

       print('''Would you like to encrypt or decrypt some text? (1 or 2)'''   )
       _lowerCamelCase				:  List[str]						=		input('''\n1. Encrypt\n2. Decrypt\n'''   )
       if option == "1":
              _lowerCamelCase				:  Tuple						=		input('''What text would you like to encrypt?: '''   )
              print('''Your encrypted text is:'''   )
              print(hc.encrypt(lowercase_   )   )
       elif option == "2":
              _lowerCamelCase				:  int						=		input('''What text would you like to decrypt?: '''   )
              print('''Your decrypted text is:'''   )
              print(hc.decrypt(lowercase_   )   )


if __name__ == "__main__":
       import doctest

       doctest.testmod()

       main()








def  __UpperCAmelCase(   lowercase_			,     lowercase_   ):
       # "extended trapezoidal rule"
       # int(f) = dx/2 * (f1 + 2f2 + ... + fn)
       _lowerCamelCase				:  int						=		(boundary[1] - boundary[0]) / steps
       _lowerCamelCase				:  Any						=		boundary[0]
       _lowerCamelCase				:  Tuple						=		boundary[1]
       _lowerCamelCase				:  Optional[Any]						=		make_points(lowercase_			,     lowercase_			,     lowercase_   )
       _lowerCamelCase				:  Dict						=		0.0
       y += (h / 2.0) * f(lowercase_   )
       for i in x_i:
              # print(i)
              y += h * f(lowercase_   )
       y += (h / 2.0) * f(lowercase_   )
       return y




def  __UpperCAmelCase(   lowercase_			,     lowercase_			,     lowercase_   ):
       _lowerCamelCase				:  Dict						=		a + h
       while x < (b - h):
              yield x
              _lowerCamelCase				:  Dict						=		x + h




def  __UpperCAmelCase(   lowercase_   ):  # enter your function here
       _lowerCamelCase				:  List[str]						=		(x - 0) * (x - 0)
       return y




def  __UpperCAmelCase(   ):
       _lowerCamelCase				:  List[Any]						=		0.0  # Lower bound of integration
       _lowerCamelCase				:  Union[str, Any]						=		1.0  # Upper bound of integration
       _lowerCamelCase				:  Dict						=		1_0.0  # define number of steps or resolution
       _lowerCamelCase				:  Optional[int]						=		[a, b]  # define boundary of integration
       _lowerCamelCase				:  str						=		method_a(lowercase_			,     lowercase_   )
       print(F"""y = {y}"""   )


if __name__ == "__main__":
       main()

