



import string

import numpy






def 	_lowerCAmelCase						(				__lowerCamelCase   :     int		,	__lowerCamelCase   :     int     ):



 """simple docstring"""





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

class       _SCREAMING_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 UpperCamelCase : x % 36 )

     lowerCAmelCase					=			numpy.vectorize(UpperCamelCase )





     def __init__(       self :							Tuple     ,  UpperCamelCase :							numpy.ndarray				)->None:
      __SCREAMING_SNAKE_CASE       :    List[Any]       =	self.modulus(UpperCamelCase				)  # mod36 calc's on the encrypt key
      self.check_determinant()  # validate the determinant of the encryption key
      __SCREAMING_SNAKE_CASE       :    Dict       =	encrypt_key.shape[0]





     def 	__snake_case    (       self :							Tuple     ,  UpperCamelCase :							str				)->int:
      return self.key_string.index(UpperCamelCase				)





     def 	__snake_case    (       self :							List[str]     ,  UpperCamelCase :							int				)->str:
      return self.key_string[round(UpperCamelCase				)]





     def 	__snake_case    (       self :							List[str]				)->None:
      __SCREAMING_SNAKE_CASE       :    Dict       =	round(numpy.linalg.det(self.encrypt_key				)				)

      if det < 0:
       __SCREAMING_SNAKE_CASE       :    List[str]       =	det % len(self.key_string				)

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





     def 	__snake_case    (       self :							List[str]     ,  UpperCamelCase :							str				)->str:
      __SCREAMING_SNAKE_CASE       :    Dict       =	[char for char in text.upper() if char in self.key_string]

      __SCREAMING_SNAKE_CASE       :    Optional[Any]       =	chars[-1]
      while len(UpperCamelCase				) % self.break_key != 0:
       chars.append(UpperCamelCase				)

      return "".join(UpperCamelCase				)





     def 	__snake_case    (       self :							Any     ,  UpperCamelCase :							str				)->str:
      __SCREAMING_SNAKE_CASE       :    Union[str, Any]       =	self.process_text(text.upper()				)
      __SCREAMING_SNAKE_CASE       :    int       =	""

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

      return encrypted





     def 	__snake_case    (       self :							int				)->numpy.ndarray:
      __SCREAMING_SNAKE_CASE       :    Union[str, Any]       =	round(numpy.linalg.det(self.encrypt_key				)				)

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

      __SCREAMING_SNAKE_CASE       :    List[str]       =	(
          det_inv
          * numpy.linalg.det(self.encrypt_key				)
          * numpy.linalg.inv(self.encrypt_key				)
      )

      return self.to_int(self.modulus(UpperCamelCase				)				)






     def 	__snake_case    (       self :							Optional[Any]     ,  UpperCamelCase :							str				)->str:
      __SCREAMING_SNAKE_CASE       :    List[Any]       =	self.make_decrypt_key()
      __SCREAMING_SNAKE_CASE       :    Optional[int]       =	self.process_text(text.upper()				)
      __SCREAMING_SNAKE_CASE       :    Dict       =	""

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

      return decrypted






def 	_lowerCAmelCase						(				):



 """simple docstring"""





 __SCREAMING_SNAKE_CASE       :    Dict       =	int(input("Enter the order of the encryption key: "     )     )
 __SCREAMING_SNAKE_CASE       :    int       =	[]

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

 __SCREAMING_SNAKE_CASE       :    str       =	HillCipher(numpy.array(__lowerCamelCase     )     )

 print("Would you like to encrypt or decrypt some text? (1 or 2)"     )
 __SCREAMING_SNAKE_CASE       :    Optional[Any]       =	input("\n1. Encrypt\n2. Decrypt\n"     )
 if option == "1":
  __SCREAMING_SNAKE_CASE       :    Optional[int]       =	input("What text would you like to encrypt?: "     )
  print("Your encrypted text is:"     )
  print(hc.encrypt(__lowerCamelCase     )     )
 elif option == "2":
  __SCREAMING_SNAKE_CASE       :    Optional[int]       =	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 importlib
import shutil
import threading
import warnings
from typing import List

import fsspec
import fsspec.asyn

from . import compression
from .hffilesystem import HfFileSystem


_lowerCamelCase						    =  importlib.util.find_spec("""s3fs""") is not None

if _has_safs:
      from .safilesystem import SaFileSystem  # noqa: F401

_lowerCamelCase						    =  [
    compression.BzaFileSystem,
    compression.GzipFileSystem,
    compression.LzaFileSystem,
    compression.XzFileSystem,
    compression.ZstdFileSystem,
]

# Register custom filesystems
for fs_class in COMPRESSION_FILESYSTEMS + [HfFileSystem]:
      if fs_class.protocol in fsspec.registry and fsspec.registry[fs_class.protocol] is not fs_class:
            warnings.warn(f'''A filesystem protocol was already set for {fs_class.protocol} and will be overwritten.''')
      fsspec.register_implementation(fs_class.protocol, fs_class, clobber=True)






def 	_lowerCAmelCase						(				__lowerCamelCase   :     str     ):



 """simple docstring"""





 if "://" in dataset_path:
  __SCREAMING_SNAKE_CASE       :    Any       =	dataset_path.split("://"     )[1]
 return dataset_path






def 	_lowerCAmelCase						(				__lowerCamelCase   :     fsspec.AbstractFileSystem     ):



 """simple docstring"""





 if fs is not None and fs.protocol != "file":
  return True
 else:
  return False






def 	_lowerCAmelCase						(				__lowerCamelCase   :     fsspec.AbstractFileSystem		,	__lowerCamelCase   :     str		,	__lowerCamelCase   :     str     ):



 """simple docstring"""





 __SCREAMING_SNAKE_CASE       :    Optional[int]       =	not is_remote_filesystem(__lowerCamelCase     )
 if is_local:
  # LocalFileSystem.mv does copy + rm, it is more efficient to simply move a local directory
  shutil.move(fs._strip_protocol(__lowerCamelCase     )		,	fs._strip_protocol(__lowerCamelCase     )     )
 else:
  fs.mv(__lowerCamelCase		,	__lowerCamelCase		,	recursive=__lowerCamelCase     )






def 	_lowerCAmelCase						(				):



 """simple docstring"""





 if hasattr(fsspec.asyn		,	"reset_lock"     ):
  # for future fsspec>2022.05.0
  fsspec.asyn.reset_lock()
 else:
  __SCREAMING_SNAKE_CASE       :    Tuple       =	None
  __SCREAMING_SNAKE_CASE       :    Optional[Any]       =	None
  __SCREAMING_SNAKE_CASE       :    Dict       =	threading.Lock()






