
'''simple docstring'''






import string

import numpy





def    UpperCAmelCase							(  UpperCAmelCase__							:							int       ,							UpperCAmelCase__							:							int):
				return b if a == 0 else greatest_common_divisor(b % a       ,							UpperCAmelCase__)




class     __snake_case		:
					_lowerCAmelCase			     =	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)
					_lowerCAmelCase			     =	numpy.vectorize(lambda a__: x % 36)

					_lowerCAmelCase			     =	numpy.vectorize(a__)
					def __init__(     self,    A      ):

									"""simple docstring"""


									lowerCamelCase					:			Optional[Any]									= self.modulus(A      )  # mod36 calc's on the encrypt key
									self.check_determinant()  # validate the determinant of the encryption key
									lowerCamelCase					:			Optional[Any]									= encrypt_key.shape[0]
					def     UpperCAmelCase_							(     self,    A      ):

									"""simple docstring"""


									return self.key_string.index(A      )
					def     UpperCAmelCase_							(     self,    A      ):

									"""simple docstring"""


									return self.key_string[round(A      )]
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									lowerCamelCase					:			int									= round(numpy.linalg.det(self.encrypt_key      )      )

									if det < 0:
													lowerCamelCase					:			Optional[int]									= det % len(self.key_string      )

									lowerCamelCase					:			Optional[int]									= len(self.key_string      )
									if greatest_common_divisor(A,    len(self.key_string      )      ) != 1:
													lowerCamelCase					:			str									= (
													    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     UpperCAmelCase_							(     self,    A      ):

									"""simple docstring"""


									lowerCamelCase					:			Tuple									= [char for char in text.upper() if char in self.key_string]

									lowerCamelCase					:			Any									= chars[-1]
									while len(A      ) % self.break_key != 0:
													chars.append(A      )

									return "".join(A      )
					def     UpperCAmelCase_							(     self,    A      ):

									"""simple docstring"""


									lowerCamelCase					:			Tuple									= self.process_text(text.upper()      )
									lowerCamelCase					:			Any									= ''

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

									return encrypted
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									lowerCamelCase					:			Dict									= round(numpy.linalg.det(self.encrypt_key      )      )

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

									lowerCamelCase					:			Dict									= (
									    det_inv
									    * numpy.linalg.det(self.encrypt_key      )
									    * numpy.linalg.inv(self.encrypt_key      )
									)

									return self.to_int(self.modulus(A      )      )




					def     UpperCAmelCase_							(     self,    A      ):

									"""simple docstring"""


									lowerCamelCase					:			Dict									= self.make_decrypt_key()
									lowerCamelCase					:			Any									= self.process_text(text.upper()      )
									lowerCamelCase					:			List[str]									= ''

									for i in range(0,    len(A      ) - self.break_key + 1,    self.break_key      ):
													lowerCamelCase					:			Any									= text[i : i + self.break_key]
													lowerCamelCase					:			Tuple									= [self.replace_letters(A      ) for char in batch]
													lowerCamelCase					:			Tuple									= numpy.array([vec]      ).T
													lowerCamelCase					:			Optional[int]									= self.modulus(decrypt_key.dot(A      )      ).T.tolist()[0]
													lowerCamelCase					:			Tuple									= ''.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					:			Optional[int]									= []

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

				lowerCamelCase					:			List[Any]									= HillCipher(numpy.array(UpperCAmelCase__))

				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					:			List[str]									= input('What text would you like to encrypt?: ')
								print('Your encrypted text is:')
								print(hc.encrypt(UpperCAmelCase__))
				elif option == "2":
								lowerCamelCase					:			Tuple									= 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()


'''simple docstring'''






# Imports
import numpy as np




class     __snake_case		:
					def __init__(     self,    A=None,    A=None,    A=None,    A=None,    A=None      ):

									"""simple docstring"""


									self.set_matricies(red=A,    green=A,    blue=A,    red_edge=A,    nir=A      )
					def     UpperCAmelCase_							(     self,    A=None,    A=None,    A=None,    A=None,    A=None      ):

									"""simple docstring"""


									if red is not None:
													lowerCamelCase					:			Optional[int]									= red
									if green is not None:
													lowerCamelCase					:			Optional[int]									= green
									if blue is not None:
													lowerCamelCase					:			List[str]									= blue
									if red_edge is not None:
													lowerCamelCase					:			Tuple									= red_edge
									if nir is not None:
													lowerCamelCase					:			Any									= nir
									return True
					def     UpperCAmelCase_							(     self,    A="",    A=None,    A=None,    A=None,    A=None,    A=None      ):

									"""simple docstring"""


									self.set_matricies(red=A,    green=A,    blue=A,    red_edge=A,    nir=A      )
									lowerCamelCase					:			Optional[int]									= {
									    'ARVI2': self.arvaa,
									    'CCCI': self.ccci,
									    'CVI': self.cvi,
									    'GLI': self.gli,
									    'NDVI': self.ndvi,
									    'BNDVI': self.bndvi,
									    'redEdgeNDVI': self.red_edge_ndvi,
									    'GNDVI': self.gndvi,
									    'GBNDVI': self.gbndvi,
									    'GRNDVI': self.grndvi,
									    'RBNDVI': self.rbndvi,
									    'PNDVI': self.pndvi,
									    'ATSAVI': self.atsavi,
									    'BWDRVI': self.bwdrvi,
									    'CIgreen': self.ci_green,
									    'CIrededge': self.ci_rededge,
									    'CI': self.ci,
									    'CTVI': self.ctvi,
									    'GDVI': self.gdvi,
									    'EVI': self.evi,
									    'GEMI': self.gemi,
									    'GOSAVI': self.gosavi,
									    'GSAVI': self.gsavi,
									    'Hue': self.hue,
									    'IVI': self.ivi,
									    'IPVI': self.ipvi,
									    'I': self.i,
									    'RVI': self.rvi,
									    'MRVI': self.mrvi,
									    'MSAVI': self.m_savi,
									    'NormG': self.norm_g,
									    'NormNIR': self.norm_nir,
									    'NormR': self.norm_r,
									    'NGRDI': self.ngrdi,
									    'RI': self.ri,
									    'S': self.s,
									    'IF': self._if,
									    'DVI': self.dvi,
									    'TVI': self.tvi,
									    'NDRE': self.ndre,
									}

									try:
													return funcs[index]()
									except KeyError:
													print('Index not in the list!'      )
													return False
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									return -0.18 + (1.17 * ((self.nir - self.red) / (self.nir + self.red)))
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									return ((self.nir - self.redEdge) / (self.nir + self.redEdge)) / (
									    (self.nir - self.red) / (self.nir + self.red)
									)
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									return self.nir * (self.red / (self.green**2))
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									return (2 * self.green - self.red - self.blue) / (
									    2 * self.green + self.red + self.blue
									)
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									return (self.nir - self.red) / (self.nir + self.red)
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									return (self.nir - self.blue) / (self.nir + self.blue)
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									return (self.redEdge - self.red) / (self.redEdge + self.red)
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									return (self.nir - self.green) / (self.nir + self.green)
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									return (self.nir - (self.green + self.blue)) / (
									    self.nir + (self.green + self.blue)
									)
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									return (self.nir - (self.green + self.red)) / (
									    self.nir + (self.green + self.red)
									)
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									return (self.nir - (self.blue + self.red)) / (self.nir + (self.blue + self.red))
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									return (self.nir - (self.green + self.red + self.blue)) / (
									    self.nir + (self.green + self.red + self.blue)
									)
					def     UpperCAmelCase_							(     self,    A=0.08,    A=1.22,    A=0.03      ):

									"""simple docstring"""


									return a * (
									    (self.nir - a * self.red - b)
									    / (a * self.nir + self.red - a * b + x * (1 + a**2))
									)
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									return (0.1 * self.nir - self.blue) / (0.1 * self.nir + self.blue)
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									return (self.nir / self.green) - 1
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									return (self.nir / self.redEdge) - 1
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									return (self.red - self.blue) / self.red
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									lowerCamelCase					:			Union[str, Any]									= self.ndvi()
									return ((ndvi + 0.5) / (abs(ndvi + 0.5      ))) * (abs(ndvi + 0.5      ) ** (1 / 2))
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									return self.nir - self.green
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									return 2.5 * (
									    (self.nir - self.red) / (self.nir + 6 * self.red - 7.5 * self.blue + 1)
									)
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									lowerCamelCase					:			str									= (2 * (self.nir**2 - self.red**2) + 1.5 * self.nir + 0.5 * self.red) / (
									    self.nir + self.red + 0.5
									)
									return n * (1 - 0.25 * n) - (self.red - 0.125) / (1 - self.red)
					def     UpperCAmelCase_							(     self,    A=0.16      ):

									"""simple docstring"""


									return (self.nir - self.green) / (self.nir + self.green + y)
					def     UpperCAmelCase_							(     self,    A=0.5      ):

									"""simple docstring"""


									return ((self.nir - self.green) / (self.nir + self.green + n)) * (1 + n)
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									return np.arctan(
									    ((2 * self.red - self.green - self.blue) / 30.5) * (self.green - self.blue)      )
					def     UpperCAmelCase_							(     self,    A=None,    A=None      ):

									"""simple docstring"""


									return (self.nir - b) / (a * self.red)
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									return (self.nir / ((self.nir + self.red) / 2)) * (self.ndvi() + 1)
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									return (self.red + self.green + self.blue) / 30.5
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									return self.nir / self.red
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									return (self.rvi() - 1) / (self.rvi() + 1)
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									return (
									    (2 * self.nir + 1)
									    - ((2 * self.nir + 1) ** 2 - 8 * (self.nir - self.red)) ** (1 / 2)
									) / 2
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									return self.green / (self.nir + self.red + self.green)
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									return self.nir / (self.nir + self.red + self.green)
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									return self.red / (self.nir + self.red + self.green)
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									return (self.green - self.red) / (self.green + self.red)
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									return (self.red - self.green) / (self.red + self.green)
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									lowerCamelCase					:			Optional[Any]									= np.max([np.max(self.red      ), np.max(self.green      ), np.max(self.blue      )]      )
									lowerCamelCase					:			Tuple									= np.min([np.min(self.red      ), np.min(self.green      ), np.min(self.blue      )]      )
									return (max_value - min_value) / max_value
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									return (2 * self.red - self.green - self.blue) / (self.green - self.blue)
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									return self.nir / self.red
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									return (self.ndvi() + 0.5) ** (1 / 2)




					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									return (self.nir - self.redEdge) / (self.nir + self.redEdge)
