


import string

import numpy



def 							UpperCamelCase_( lowerCamelCase_				,					lowerCamelCase_					)       ->		int:
    return b if a == 0 else greatest_common_divisor(b % a				,					lowerCamelCase_					)






class _lowerCamelCase:
       lowercase_					:      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)
       lowercase_					:      Union[str, Any]       					=     numpy.vectorize(lambda _a  : x % 36  )

       lowercase_					:      Optional[Any]       					=     numpy.vectorize(_a  )
       def __init__(   self, lowerCamelCase)			->  None:




           """simple docstring"""

           _lowercase			:				List[str] 						=						self.modulus(lowerCamelCase)  # mod36 calc's on the encrypt key
           self.check_determinant()  # validate the determinant of the encryption key
           _lowercase			:				Optional[Any] 						=						encrypt_key.shape[0]
       def      UpperCamelCase	(   self, lowerCamelCase)			->  int:




           """simple docstring"""

           return self.key_string.index(lowerCamelCase)
       def      UpperCamelCase	(   self, lowerCamelCase)			->  str:




           """simple docstring"""

           return self.key_string[round(lowerCamelCase)]
       def      UpperCamelCase	(   self)			->  None:




           """simple docstring"""

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

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

           _lowercase			:				str 						=						len(self.key_string)
           if greatest_common_divisor(lowerCamelCase, len(self.key_string)) != 1:
               _lowercase			:				Any 						=						(
                   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      UpperCamelCase	(   self, lowerCamelCase)			->  str:




           """simple docstring"""

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

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

           return "".join(lowerCamelCase)
       def      UpperCamelCase	(   self, lowerCamelCase)			->  str:




           """simple docstring"""

           _lowercase			:				Dict 						=						self.process_text(text.upper())
           _lowercase			:				List[Any] 						=						''

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

           return encrypted
       def      UpperCamelCase	(   self)			->  numpy.ndarray:




           """simple docstring"""

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

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

           _lowercase			:				Optional[int] 						=						(
               det_inv
               * numpy.linalg.det(self.encrypt_key)
               * numpy.linalg.inv(self.encrypt_key)
           )

           return self.to_int(self.modulus(lowerCamelCase))




       def      UpperCamelCase	(   self, lowerCamelCase)			->  str:




           """simple docstring"""

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

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

           return decrypted



def 							UpperCamelCase_( )       ->		None:
    _lowercase			:				str 						=						int(input('Enter the order of the encryption key: '					)					)
    _lowercase			:				List[Any] 						=						[]

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

    _lowercase			:				str 						=						HillCipher(numpy.array(lowerCamelCase_					)					)

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

try:
 from .build_directory_md import good_file_paths
except ImportError:
 from build_directory_md import good_file_paths  # type: ignore

SCREAMING_SNAKE_CASE			: int				   =					list(good_file_paths())
assert filepaths, "good_file_paths() failed!"

SCREAMING_SNAKE_CASE			: Dict				   =					[file for file in filepaths if file != file.lower()]
if upper_files:
 print(F"{len(upper_files)} files contain uppercase characters:")
 print("\n".join(upper_files) + "\n")

SCREAMING_SNAKE_CASE			: List[Any]				   =					[file for file in filepaths if " " in file]
if space_files:
 print(F"{len(space_files)} files contain space characters:")
 print("\n".join(space_files) + "\n")

SCREAMING_SNAKE_CASE			: Any				   =					[file for file in filepaths if "-" in file]
if hyphen_files:
 print(F"{len(hyphen_files)} files contain hyphen characters:")
 print("\n".join(hyphen_files) + "\n")

SCREAMING_SNAKE_CASE			: str				   =					[file for file in filepaths if os.sep not in file]
if nodir_files:
 print(F"{len(nodir_files)} files are not in a directory:")
 print("\n".join(nodir_files) + "\n")

SCREAMING_SNAKE_CASE			: Tuple				   =					len(upper_files + space_files + hyphen_files + nodir_files)
if bad_files:
 import sys

 sys.exit(bad_files)


