


import os
import sys

from . import rsa_key_generator as rkg

lowerCAmelCase__						=			1_28
lowerCAmelCase__						=			2_56
def 							_UpperCAmelCase    (UpperCamelCase__					:  str    ,							UpperCamelCase__					:  int = DEFAULT_BLOCK_SIZE						):
       _A				:	Dict       =			message.encode("ascii"						)

       _A				:	str       =			[]
       for block_start in range(0    ,							len(UpperCamelCase__						)    ,							UpperCamelCase__						):
              _A				:	int       =			0
              for i in range(UpperCamelCase__    ,							min(block_start + block_size    ,							len(UpperCamelCase__						)						)						):
                     block_int += message_bytes[i] * (BYTE_SIZE ** (i % block_size))
              block_ints.append(UpperCamelCase__						)
       return block_ints
def 							_UpperCAmelCase    (UpperCamelCase__					:  list[int]    ,							UpperCamelCase__					:  int    ,							UpperCamelCase__					:  int = DEFAULT_BLOCK_SIZE						):
       _A				:	list[str]       =			[]
       for block_int in block_ints:
              _A				:	list[str]       =			[]
              for i in range(block_size - 1    ,							-1    ,							-1						):
                     if len(UpperCamelCase__						) + i < message_length:
                            _A				:	List[Any]       =			block_int // (BYTE_SIZE**i)
                            _A				:	Dict       =			block_int % (BYTE_SIZE**i)
                            block_message.insert(0    ,							chr(UpperCamelCase__						)						)
              message.extend(UpperCamelCase__						)
       return "".join(UpperCamelCase__						)
def 							_UpperCAmelCase    (UpperCamelCase__					:  str    ,							UpperCamelCase__					:  tuple[int, int]    ,							UpperCamelCase__					:  int = DEFAULT_BLOCK_SIZE						):
       _A				:	str       =			[]
       _A   ,      _A				:	str       =			key

       for block in get_blocks_from_text(UpperCamelCase__    ,							UpperCamelCase__						):
              encrypted_blocks.append(pow(UpperCamelCase__    ,							UpperCamelCase__    ,							UpperCamelCase__						)						)
       return encrypted_blocks
def 							_UpperCAmelCase    (UpperCamelCase__					:  list[int]    ,							UpperCamelCase__					:  int    ,							UpperCamelCase__					:  tuple[int, int]    ,							UpperCamelCase__					:  int = DEFAULT_BLOCK_SIZE    ,							):
       _A				:	List[str]       =			[]
       _A   ,      _A				:	Dict       =			key
       for block in encrypted_blocks:
              decrypted_blocks.append(pow(UpperCamelCase__    ,							UpperCamelCase__    ,							UpperCamelCase__						)						)
       return get_text_from_blocks(UpperCamelCase__    ,							UpperCamelCase__    ,							UpperCamelCase__						)
def 							_UpperCAmelCase    (UpperCamelCase__					:  str						):
       with open(UpperCamelCase__						) as fo:
              _A				:	List[Any]       =			fo.read()
       _A   ,      _A   ,      _A				:	Any       =			content.split(","						)
       return (int(UpperCamelCase__						), int(UpperCamelCase__						), int(UpperCamelCase__						))
def 							_UpperCAmelCase    (UpperCamelCase__					:  str    ,							UpperCamelCase__					:  str    ,							UpperCamelCase__					:  str    ,							UpperCamelCase__					:  int = DEFAULT_BLOCK_SIZE    ,							):
       _A   ,      _A   ,      _A				:	str       =			read_key_file(UpperCamelCase__						)
       if key_size < block_size * 8:
              sys.exit(
                  "ERROR: Block size is {} bits and key size is {} bits. The RSA cipher "
                  "requires the block size to be equal to or greater than the key size. "
                  "Either decrease the block size or use different keys.".format(
                      block_size * 8    ,							UpperCamelCase__						)						)

       _A				:	Tuple       =			[str(UpperCamelCase__						) for i in encrypt_message(UpperCamelCase__    ,							(n, e)    ,							UpperCamelCase__						)]

       _A				:	Any       =			",".join(UpperCamelCase__						)
       _A				:	Any       =			f"{len(UpperCamelCase__						)}_{block_size}_{encrypted_content}"
       with open(UpperCamelCase__    ,							"w"						) as fo:
              fo.write(UpperCamelCase__						)
       return encrypted_content
def 							_UpperCAmelCase    (UpperCamelCase__					:  str    ,							UpperCamelCase__					:  str						):
       _A   ,      _A   ,      _A				:	Tuple       =			read_key_file(UpperCamelCase__						)
       with open(UpperCamelCase__						) as fo:
              _A				:	Tuple       =			fo.read()
       _A   ,      _A   ,      _A				:	Dict       =			content.split("_"						)
       _A				:	Any       =			int(UpperCamelCase__						)
       _A				:	int       =			int(UpperCamelCase__						)

       if key_size < block_size * 8:
              sys.exit(
                  "ERROR: Block size is {} bits and key size is {} bits. The RSA cipher "
                  "requires the block size to be equal to or greater than the key size. "
                  "Did you specify the correct key file and encrypted file?".format(
                      block_size * 8    ,							UpperCamelCase__						)						)

       _A				:	Dict       =			[]
       for block in encrypted_message.split(","						):
              encrypted_blocks.append(int(UpperCamelCase__						)						)

       return decrypt_message(UpperCamelCase__    ,							UpperCamelCase__    ,							(n, d)    ,							UpperCamelCase__						)
def 							_UpperCAmelCase    ():
       _A				:	Optional[int]       =			"encrypted_file.txt"
       _A				:	List[Any]       =			input(r"Encrypt\Decrypt [e\d]: "						)

       if response.lower().startswith("e"						):
              _A				:	Dict       =			"encrypt"
       elif response.lower().startswith("d"						):
              _A				:	List[str]       =			"decrypt"

       if mode == "encrypt":
              if not os.path.exists("rsa_pubkey.txt"						):
                     rkg.make_key_files("rsa"    ,							1024						)

              _A				:	Optional[int]       =			input("\nEnter message: "						)
              _A				:	List[Any]       =			"rsa_pubkey.txt"
              print(f"Encrypting and writing to {filename}..."						)
              _A				:	List[Any]       =			encrypt_and_write_to_file(UpperCamelCase__    ,							UpperCamelCase__    ,							UpperCamelCase__						)

              print("\nEncrypted text:"						)
              print(UpperCamelCase__						)

       elif mode == "decrypt":
              _A				:	Dict       =			"rsa_privkey.txt"
              print(f"Reading from {filename} and decrypting..."						)
              _A				:	List[str]       =			read_from_file_and_decrypt(UpperCamelCase__    ,							UpperCamelCase__						)
              print("writing decryption to rsa_decryption.txt..."						)
              with open("rsa_decryption.txt"    ,							"w"						) as dec:
                     dec.write(UpperCamelCase__						)

              print("\nDecryption:"						)
              print(UpperCamelCase__						)


if __name__ == "__main__":
    main()




import json
from typing import List, Optional, Tuple

from tokenizers import normalizers

from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import logging
from .tokenization_splinter import SplinterTokenizer


lowerCAmelCase__						=			logging.get_logger(__name__)

lowerCAmelCase__						=			{'vocab_file': 'vocab.txt'}

lowerCAmelCase__						=			{
    'vocab_file': {
        'tau/splinter-base': 'https://huggingface.co/tau/splinter-base/resolve/main/vocab.txt',
        'tau/splinter-base-qass': 'https://huggingface.co/tau/splinter-base-qass/resolve/main/vocab.txt',
        'tau/splinter-large': 'https://huggingface.co/tau/splinter-large/resolve/main/vocab.txt',
        'tau/splinter-large-qass': 'https://huggingface.co/tau/splinter-large-qass/resolve/main/vocab.txt',
    }
}

lowerCAmelCase__						=			{
    'tau/splinter-base': 5_12,
    'tau/splinter-base-qass': 5_12,
    'tau/splinter-large': 5_12,
    'tau/splinter-large-qass': 5_12,
}

lowerCAmelCase__						=			{
    'tau/splinter-base': {'do_lower_case': False},
    'tau/splinter-base-qass': {'do_lower_case': False},
    'tau/splinter-large': {'do_lower_case': False},
    'tau/splinter-large-qass': {'do_lower_case': False},
}







class 					lowerCAmelCase__	(    a):




     '''simple docstring'''
     __SCREAMING_SNAKE_CASE        =			VOCAB_FILES_NAMES
     __SCREAMING_SNAKE_CASE        =			PRETRAINED_VOCAB_FILES_MAP
     __SCREAMING_SNAKE_CASE        =			PRETRAINED_INIT_CONFIGURATION
     __SCREAMING_SNAKE_CASE        =			PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
     __SCREAMING_SNAKE_CASE        =			SplinterTokenizer


     def __init__(						self			,						__lowerCamelCase=None			,						__lowerCamelCase=None			,						__lowerCamelCase=True			,						__lowerCamelCase="[UNK]"			,						__lowerCamelCase="[SEP]"			,						__lowerCamelCase="[PAD]"			,						__lowerCamelCase="[CLS]"			,						__lowerCamelCase="[MASK]"			,						__lowerCamelCase="[QUESTION]"			,						__lowerCamelCase=True			,						__lowerCamelCase=None			,						**__lowerCamelCase			,						)      ->    Union[str, Any]:
            super().__init__(
                __lowerCamelCase			,						tokenizer_file=__lowerCamelCase			,						do_lower_case=__lowerCamelCase			,						unk_token=__lowerCamelCase			,						sep_token=__lowerCamelCase			,						pad_token=__lowerCamelCase			,						cls_token=__lowerCamelCase			,						mask_token=__lowerCamelCase			,						tokenize_chinese_chars=__lowerCamelCase			,						strip_accents=__lowerCamelCase			,						additional_special_tokens=(question_token,)			,						**__lowerCamelCase			,						)

            _A				:	Tuple       =			json.loads(self.backend_tokenizer.normalizer.__getstate__())
            if (
                pre_tok_state.get("lowercase"			,						__lowerCamelCase) != do_lower_case
                or pre_tok_state.get("strip_accents"			,						__lowerCamelCase) != strip_accents
            ):
                   _A				:	Dict       =			getattr(__lowerCamelCase			,						pre_tok_state.pop("type"))
                   _A				:	List[str]       =			do_lower_case
                   _A				:	Any       =			strip_accents
                   _A				:	int       =			pre_tok_class(**__lowerCamelCase)

            _A				:	int       =			do_lower_case


     @property
     def 			_lowerCamelCase			(						self)      ->    str:
            return self.convert_tokens_to_ids(self.question_token)


     def 			_lowerCamelCase			(						self			,						__lowerCamelCase			,						__lowerCamelCase = None)      ->    List[int]:
            if token_ids_a is None:
                   return [self.cls_token_id] + token_ids_a + [self.sep_token_id]

            _A				:	Tuple       =			[self.cls_token_id]
            _A				:	str       =			[self.sep_token_id]
            _A				:	int       =			[self.question_token_id] + [self.convert_tokens_to_ids(".")]
            if self.padding_side == "right":
                   # Input is question-then-context
                   return cls + token_ids_a + question_suffix + sep + token_ids_a + sep
            else:
                   # Input is context-then-question
                   return cls + token_ids_a + sep + token_ids_a + question_suffix + sep


     def 			_lowerCamelCase			(						self			,						__lowerCamelCase			,						__lowerCamelCase = None)      ->    List[int]:
            _A				:	str       =			[self.sep_token_id]
            _A				:	int       =			[self.cls_token_id]
            _A				:	Union[str, Any]       =			[self.question_token_id] + [self.convert_tokens_to_ids(".")]
            if token_ids_a is None:
                   return len(cls + token_ids_a + sep) * [0]

            if self.padding_side == "right":
                   # Input is question-then-context
                   return len(cls + token_ids_a + question_suffix + sep) * [0] + len(token_ids_a + sep) * [1]
            else:
                   # Input is context-then-question
                   return len(cls + token_ids_a + sep) * [0] + len(token_ids_a + question_suffix + sep) * [1]


     def 			_lowerCamelCase			(						self			,						__lowerCamelCase			,						__lowerCamelCase = None)      ->    Tuple[str]:
            _A				:	Tuple       =			self._tokenizer.model.save(__lowerCamelCase			,						name=__lowerCamelCase)
            return tuple(__lowerCamelCase)
