





import os
from pathlib import Path
from unittest.mock import patch

import pytest
import zstandard as zstd

from datasets.download.download_config import DownloadConfig
from datasets.utils.file_utils import (
    OfflineModeIsEnabled,
    cached_path,
    fsspec_get,
    fsspec_head,
    ftp_get,
    ftp_head,
    get_from_cache,
    http_get,
    http_head,
)


snake_case 				=       """\\n    Text data.\n    Second line of data."""

snake_case 				=       """file"""

@pytest.fixture(scope='session'     )
def 							SCREAMING_SNAKE_CASE__       (  snake_case__  :int     )      ->						List[str]:
    _lowercase							= tmp_path_factory.mktemp('data'     ) / (FILE_PATH + '.zstd')
    _lowercase							= bytes(_lowercase			,							'utf-8'     )
    with zstd.open(_lowercase			,							'wb'     ) as f:
        f.write(_lowercase     )
    return path

@pytest.fixture
def 							SCREAMING_SNAKE_CASE__       (  snake_case__  :Optional[Any]     )      ->						Optional[Any]:







    with open(os.path.join(tmpfs.local_root_dir			,							_lowercase     )			,							'w'     ) as f:
        f.write(_lowercase     )
    return FILE_PATH

@pytest.mark.parametrize('compression_format'			,							['gzip', 'xz', 'zstd']     )
def 							SCREAMING_SNAKE_CASE__       (  snake_case__  :Union[str, Any]			,							snake_case__  :Any			,							snake_case__  :Optional[int]			,							snake_case__  :List[str]			,							snake_case__  :Optional[Any]			,							snake_case__  :Optional[int]     )      ->						List[Any]:
    _lowercase							= {'gzip': gz_file, 'xz': xz_file, 'zstd': zstd_path}
    _lowercase							= input_paths[compression_format]
    _lowercase							= tmp_path / 'cache'
    _lowercase							= DownloadConfig(cache_dir=_lowercase			,							extract_compressed_file=_lowercase     )
    _lowercase							= cached_path(_lowercase			,							download_config=_lowercase     )
    with open(_lowercase     ) as f:
        _lowercase							= f.read()
    with open(_lowercase     ) as f:
        _lowercase							= f.read()
    assert extracted_file_content == expected_file_content

@pytest.mark.parametrize('default_extracted'			,							[True, False]     )
@pytest.mark.parametrize('default_cache_dir'			,							[True, False]     )
def 							SCREAMING_SNAKE_CASE__       (  snake_case__  :List[Any]			,							snake_case__  :Any			,							snake_case__  :Optional[int]			,							snake_case__  :Dict			,							snake_case__  :List[str]     )      ->						int:
    _lowercase							= 'custom_cache'
    _lowercase							= 'custom_extracted_dir'
    _lowercase							= tmp_path / 'custom_extracted_path'
    if default_extracted:
        _lowercase							= ('downloads' if default_cache_dir else custom_cache_dir, 'extracted')
    else:
        monkeypatch.setattr('datasets.config.EXTRACTED_DATASETS_DIR'			,							_lowercase     )
        monkeypatch.setattr('datasets.config.EXTRACTED_DATASETS_PATH'			,							str(_lowercase     )     )
        _lowercase							= custom_extracted_path.parts[-2:] if default_cache_dir else (custom_cache_dir, custom_extracted_dir)

    _lowercase							= xz_file
    _lowercase							= (
        DownloadConfig(extract_compressed_file=_lowercase     )
        if default_cache_dir
        else DownloadConfig(cache_dir=tmp_path / custom_cache_dir			,							extract_compressed_file=_lowercase     )
    )
    _lowercase							= cached_path(_lowercase			,							download_config=_lowercase     )
    assert Path(_lowercase     ).parent.parts[-2:] == expected

def 							SCREAMING_SNAKE_CASE__       (  snake_case__  :int     )      ->						List[str]:
    _lowercase							= str(Path(_lowercase     ).resolve()     )
    assert cached_path(_lowercase     ) == text_file
    # relative path
    _lowercase							= str(Path(_lowercase     ).resolve().relative_to(Path(os.getcwd()     )     )     )
    assert cached_path(_lowercase     ) == text_file

def 							SCREAMING_SNAKE_CASE__       (  snake_case__  :List[Any]     )      ->						Union[str, Any]:
    _lowercase							= str(tmp_path.resolve() / '__missing_file__.txt'     )
    with pytest.raises(_lowercase     ):
        cached_path(_lowercase     )
    # relative path
    _lowercase							= './__missing_file__.txt'
    with pytest.raises(_lowercase     ):
        cached_path(_lowercase     )

def 							SCREAMING_SNAKE_CASE__       (  snake_case__  :Optional[int]     )      ->						Tuple:
    _lowercase							= get_from_cache(F"""tmp://{tmpfs_file}"""     )
    with open(_lowercase     ) as f:
        _lowercase							= f.read()
    assert output_file_content == FILE_CONTENT

@patch('datasets.config.HF_DATASETS_OFFLINE'			,							_lowercase     )
def 							SCREAMING_SNAKE_CASE__       (  )      ->						List[str]:







    with pytest.raises(_lowercase     ):
        cached_path('https://huggingface.co'     )

@patch('datasets.config.HF_DATASETS_OFFLINE'			,							_lowercase     )
def 							SCREAMING_SNAKE_CASE__       (  snake_case__  :List[str]     )      ->						str:
    _lowercase							= tmp_path_factory.mktemp('data'     ) / 'file.html'
    with pytest.raises(_lowercase     ):
        http_get('https://huggingface.co'			,							temp_file=_lowercase     )
    with pytest.raises(_lowercase     ):
        http_head('https://huggingface.co'     )

@patch('datasets.config.HF_DATASETS_OFFLINE'			,							_lowercase     )
def 							SCREAMING_SNAKE_CASE__       (  snake_case__  :Dict     )      ->						Dict:
    _lowercase							= tmp_path_factory.mktemp('data'     ) / 'file.html'
    with pytest.raises(_lowercase     ):
        ftp_get('ftp://huggingface.co'			,							temp_file=_lowercase     )
    with pytest.raises(_lowercase     ):
        ftp_head('ftp://huggingface.co'     )







@patch('datasets.config.HF_DATASETS_OFFLINE'			,							_lowercase     )
def 							SCREAMING_SNAKE_CASE__       (  snake_case__  :List[Any]     )      ->						Optional[Any]:
    _lowercase							= tmp_path_factory.mktemp('data'     ) / 'file.html'
    with pytest.raises(_lowercase     ):
        fsspec_get('s3://huggingface.co'			,							temp_file=_lowercase     )
    with pytest.raises(_lowercase     ):
        fsspec_head('s3://huggingface.co'     )






import string

import numpy

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





class 				A_				:







       """simple docstring"""





       SCREAMING_SNAKE_CASE_      : Dict      =  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)
       SCREAMING_SNAKE_CASE_      : Dict      =  numpy.vectorize(lambda UpperCAmelCase	: x % 3_6	)

       SCREAMING_SNAKE_CASE_      : List[Any]      =  numpy.vectorize(UpperCAmelCase	)







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







       def    __UpperCAmelCase (    self	:	Tuple						,__A	:	str  )						->					int:
         return self.key_string.index(__A  )







       def    __UpperCAmelCase (    self	:	Optional[int]						,__A	:	int  )						->					str:
         return self.key_string[round(__A  )]







       def    __UpperCAmelCase (    self	:	str  )						->					None:
         _lowercase							= round(numpy.linalg.det(self.encrypt_key  )  )

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

         _lowercase							= len(self.key_string  )
         if greatest_common_divisor(__A						,len(self.key_string  )  ) != 1:
           _lowercase							= (
               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	:	Any						,__A	:	str  )						->					str:
         _lowercase							= [char for char in text.upper() if char in self.key_string]

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

         return "".join(__A  )







       def    __UpperCAmelCase (    self	:	Optional[int]						,__A	:	str  )						->					str:
         _lowercase							= self.process_text(text.upper()  )
         _lowercase							= ''

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

         return encrypted







       def    __UpperCAmelCase (    self	:	List[Any]  )						->					numpy.ndarray:
         _lowercase							= round(numpy.linalg.det(self.encrypt_key  )  )

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

         _lowercase							= (
             det_inv
             * numpy.linalg.det(self.encrypt_key  )
             * numpy.linalg.inv(self.encrypt_key  )
         )

         return self.to_int(self.modulus(__A  )  )







       def    __UpperCAmelCase (    self	:	Tuple						,__A	:	str  )						->					str:
         _lowercase							= self.make_decrypt_key()
         _lowercase							= self.process_text(text.upper()  )
         _lowercase							= ''

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

         return decrypted

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

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

  _lowercase							= HillCipher(numpy.array(snake_case__     )     )

  print('Would you like to encrypt or decrypt some text? (1 or 2)'     )
  _lowercase							= input('\n1. Encrypt\n2. Decrypt\n'     )
  if option == "1":
    _lowercase							= input('What text would you like to encrypt?: '     )
    print('Your encrypted text is:'     )
    print(hc.encrypt(snake_case__     )     )
  elif option == "2":
    _lowercase							= input('What text would you like to decrypt?: '     )
    print('Your decrypted text is:'     )
    print(hc.decrypt(snake_case__     )     )


if __name__ == "__main__":
      import doctest

      doctest.testmod()

      main()