





'''simple docstring'''







import os
import re
import unicodedata
from shutil import copyfile
from typing import Any, Dict, List, Optional, Tuple

import sentencepiece as spm

from ...tokenization_utils import AddedToken, PreTrainedTokenizer
from ...utils import logging


A						    =							logging.get_logger(__name__)
A						    =							{"""vocab_file""": """spiece.model"""}

A						    =							{
    """vocab_file""": {
        """google/fnet-base""": """https://huggingface.co/google/fnet-base/resolve/main/spiece.model""",
        """google/fnet-large""": """https://huggingface.co/google/fnet-large/resolve/main/spiece.model""",
    },
}

A						    =							{
    """google/fnet-base""": 5_12,
    """google/fnet-large""": 5_12,
}

A						    =							"""▁"""



class 							__SCREAMING_SNAKE_CASE			(       _SCREAMING_SNAKE_CASE      ):
      '''simple docstring'''



      lowerCAmelCase__       :      Tuple 		=		VOCAB_FILES_NAMES
      lowerCAmelCase__       :      str 		=		PRETRAINED_VOCAB_FILES_MAP
      lowerCAmelCase__       :      List[str] 		=		PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
      lowerCAmelCase__       :      str 		=		["input_ids", "token_type_ids"]

      def __init__(							self    : List[str]   ,UpperCamelCase    : str   ,UpperCamelCase    : Optional[Any]=False   ,UpperCamelCase    : str=True   ,UpperCamelCase    : Dict=True   ,UpperCamelCase    : List[Any]="<unk>"   ,UpperCamelCase    : Tuple="[SEP]"   ,UpperCamelCase    : int="<pad>"   ,UpperCamelCase    : Any="[CLS]"   ,UpperCamelCase    : Optional[int]="[MASK]"   ,UpperCamelCase    : List[str] = None   ,**UpperCamelCase    : List[str]   ,)		->  None:
           # Mask token behave like a normal word, i.e. include the space before it and
           # is included in the raw text, there should be a match in a non-normalized sentence.
           _lowercase							:      Any  						=							(
               AddedToken(__A   ,lstrip=__A   ,rstrip=__A   ,normalized=__A  )
               if isinstance(__A   ,__A  )
               else mask_token
           )

           _lowercase							:      List[Any]  						=							{} if sp_model_kwargs is None else sp_model_kwargs

           super().__init__(
               do_lower_case=__A   ,remove_space=__A   ,keep_accents=__A   ,unk_token=__A   ,sep_token=__A   ,pad_token=__A   ,cls_token=__A   ,mask_token=__A   ,sp_model_kwargs=self.sp_model_kwargs   ,**__A   ,)

           _lowercase							:      int  						=							do_lower_case
           _lowercase							:      List[str]  						=							remove_space
           _lowercase							:      Tuple  						=							keep_accents
           _lowercase							:      Any  						=							vocab_file

           _lowercase							:      int  						=							spm.SentencePieceProcessor(**self.sp_model_kwargs  )
           self.sp_model.Load(__A  )

      @property
      def   _lowerCamelCase		(							self    : Optional[int]  )		->  Optional[int]:
           return len(self.sp_model  )

      def   _lowerCamelCase		(							self    : List[str]  )		->  int:
           _lowercase							:      Union[str, Any]  						=							{self.convert_ids_to_tokens(__A  ): i for i in range(self.vocab_size  )}
           vocab.update(self.added_tokens_encoder  )
           return vocab

      def __getstate__(							self    : Optional[Any]  )		->  List[Any]:
           _lowercase							:      Union[str, Any]  						=							self.__dict__.copy()
           _lowercase							:      Any  						=							None
           return state

      def __setstate__(							self    : Optional[int]   ,UpperCamelCase    : Any  )		->  Any:
           _lowercase							:      Dict  						=							d

           # for backward compatibility
           if not hasattr(self   ,'sp_model_kwargs'  ):
                _lowercase							:      List[str]  						=							{}

           _lowercase							:      Optional[int]  						=							spm.SentencePieceProcessor(**self.sp_model_kwargs  )
           self.sp_model.Load(self.vocab_file  )

      def   _lowerCamelCase		(							self    : Tuple   ,UpperCamelCase    : Optional[Any]  )		->  Optional[Any]:
           if self.remove_space:
                _lowercase							:      List[str]  						=							' '.join(inputs.strip().split()  )
           else:
                _lowercase							:      Dict  						=							inputs
           _lowercase							:      int  						=							outputs.replace('``'   ,'"'  ).replace('\'\''   ,'"'  )

           if not self.keep_accents:
                _lowercase							:      str  						=							unicodedata.normalize('NFKD'   ,__A  )
                _lowercase							:      Optional[int]  						=							''.join([c for c in outputs if not unicodedata.combining(__A  )]  )
           if self.do_lower_case:
                _lowercase							:      Tuple  						=							outputs.lower()

           return outputs

      def   _lowerCamelCase		(							self    : Any   ,UpperCamelCase    : List[Any]  )		->  List[str]:
           _lowercase							:      Any  						=							self.preprocess_text(__A  )
           _lowercase							:      Optional[Any]  						=							self.sp_model.encode(__A   ,out_type=__A  )
           _lowercase							:      Tuple  						=							[]
           for piece in pieces:
                if len(__A  ) > 1 and piece[-1] == str(','  ) and piece[-2].isdigit():
                     _lowercase							:      Optional[Any]  						=							self.sp_model.EncodeAsPieces(piece[:-1].replace(__A   ,''  )  )
                     if piece[0] != SPIECE_UNDERLINE and cur_pieces[0][0] == SPIECE_UNDERLINE:
                          if len(cur_pieces[0]  ) == 1:
                               _lowercase							:      Any  						=							cur_pieces[1:]
                          else:
                               _lowercase							:      int  						=							cur_pieces[0][1:]
                     cur_pieces.append(piece[-1]  )
                     new_pieces.extend(__A  )
                else:
                     new_pieces.append(__A  )

           return new_pieces

      def   _lowerCamelCase		(							self    : str   ,UpperCamelCase    : Optional[Any]  )		->  Dict:
           return self.sp_model.PieceToId(__A  )

      def   _lowerCamelCase		(							self    : Tuple   ,UpperCamelCase    : int  )		->  Dict:
           return self.sp_model.IdToPiece(__A  )

      def   _lowerCamelCase		(							self    : Union[str, Any]   ,UpperCamelCase    : Dict  )		->  int:
           _lowercase							:      str  						=							[]
           _lowercase							:      Any  						=							''
           _lowercase							:      Tuple  						=							False
           for token in tokens:
                # make sure that special tokens are not decoded using sentencepiece model
                if token in self.all_special_tokens:
                     if not prev_is_special:
                          out_string += " "
                     out_string += self.sp_model.decode(__A  ) + token
                     _lowercase							:      Union[str, Any]  						=							True
                     _lowercase							:      Optional[int]  						=							[]
                else:
                     current_sub_tokens.append(__A  )
                     _lowercase							:      Tuple  						=							False
           out_string += self.sp_model.decode(__A  )
           return out_string.strip()

      def   _lowerCamelCase		(							self    : Dict   ,UpperCamelCase    : List[str]   ,UpperCamelCase    : Union[str, Any] = False   ,UpperCamelCase    : int = None   ,UpperCamelCase    : str = True   ,**UpperCamelCase    : str   ,)		->  str:
           _lowercase							:      Dict  						=							kwargs.pop('use_source_tokenizer'   ,__A  )

           _lowercase							:      Any  						=							self.convert_ids_to_tokens(__A   ,skip_special_tokens=__A  )

           # To avoid mixing byte-level and unicode for byte-level BPT
           # we need to build string separately for added tokens and byte-level tokens
           # cf. https://github.com/huggingface/transformers/issues/1133
           _lowercase							:      Optional[int]  						=							[]
           _lowercase							:      List[str]  						=							[]
           for token in filtered_tokens:
                if skip_special_tokens and token in self.all_special_ids:
                     continue
                if token in self.added_tokens_encoder:
                     if current_sub_text:
                          sub_texts.append(self.convert_tokens_to_string(__A  )  )
                          _lowercase							:      Any  						=							[]
                     sub_texts.append(__A  )
                else:
                     current_sub_text.append(__A  )
           if current_sub_text:
                sub_texts.append(self.convert_tokens_to_string(__A  )  )

           # Mimic the behavior of the Rust tokenizer:
           # No space after <unk>
           if spaces_between_special_tokens:
                _lowercase							:      List[str]  						=							re.sub(R'(<unk>) '   ,R'\1'   ,' '.join(__A  )  )
           else:
                _lowercase							:      List[Any]  						=							''.join(__A  )

           _lowercase							:      Dict  						=							(
               clean_up_tokenization_spaces
               if clean_up_tokenization_spaces is not None
               else self.clean_up_tokenization_spaces
           )
           if clean_up_tokenization_spaces:
                _lowercase							:      int  						=							self.clean_up_tokenization(__A  )
                return clean_text
           else:
                return text

      def   _lowerCamelCase		(							self    : Optional[int]   ,UpperCamelCase    : Union[str, Any]   ,UpperCamelCase    : Tuple = None  )		->  List[int]:
           _lowercase							:      Optional[int]  						=							[self.sep_token_id]
           _lowercase							:      str  						=							[self.cls_token_id]
           if token_ids_a is None:
                return cls + token_ids_a + sep
           return cls + token_ids_a + sep + token_ids_a + sep

      def   _lowerCamelCase		(							self    : List[Any]   ,UpperCamelCase    : Tuple   ,UpperCamelCase    : Tuple = None   ,UpperCamelCase    : Optional[int] = False  )		->  List[int]:

           if already_has_special_tokens:
                return super().get_special_tokens_mask(
                    token_ids_a=__A   ,token_ids_a=__A   ,already_has_special_tokens=__A  )

           if token_ids_a is not None:
                return [1] + ([0] * len(__A  )) + [1] + ([0] * len(__A  )) + [1]
           return [1] + ([0] * len(__A  )) + [1]

      def   _lowerCamelCase		(							self    : Any   ,UpperCamelCase    : Optional[Any]   ,UpperCamelCase    : Union[str, Any] = None  )		->  List[int]:
           _lowercase							:      Any  						=							[self.sep_token_id]
           _lowercase							:      Any  						=							[self.cls_token_id]

           if token_ids_a is None:
                return len(cls + token_ids_a + sep  ) * [0]
           return len(cls + token_ids_a + sep  ) * [0] + len(token_ids_a + sep  ) * [1]



      def   _lowerCamelCase		(							self    : str   ,UpperCamelCase    : Optional[Any]   ,UpperCamelCase    : str = None  )		->  Tuple[str]:
           if not os.path.isdir(__A  ):
                logger.error(F'''Vocabulary path ({save_directory}) should be a directory'''  )
                return
           _lowercase							:      List[Any]  						=							os.path.join(
               __A   ,(filename_prefix + '-' if filename_prefix else '') + VOCAB_FILES_NAMES['vocab_file']  )

           if os.path.abspath(self.vocab_file  ) != os.path.abspath(__A  ) and os.path.isfile(self.vocab_file  ):
                copyfile(self.vocab_file   ,__A  )
           elif not os.path.isfile(self.vocab_file  ):
                with open(__A   ,'wb'  ) as fi:
                     _lowercase							:      Dict  						=							self.sp_model.serialized_model_proto()
                     fi.write(__A  )

           return (out_vocab_file,)






'''simple docstring'''







A						    =							{
    '''A''': ('''ABCDEFGHIJKLM''', '''NOPQRSTUVWXYZ'''),
    '''B''': ('''ABCDEFGHIJKLM''', '''NOPQRSTUVWXYZ'''),
    '''C''': ('''ABCDEFGHIJKLM''', '''ZNOPQRSTUVWXY'''),
    '''D''': ('''ABCDEFGHIJKLM''', '''ZNOPQRSTUVWXY'''),
    '''E''': ('''ABCDEFGHIJKLM''', '''YZNOPQRSTUVWX'''),
    '''F''': ('''ABCDEFGHIJKLM''', '''YZNOPQRSTUVWX'''),
    '''G''': ('''ABCDEFGHIJKLM''', '''XYZNOPQRSTUVW'''),
    '''H''': ('''ABCDEFGHIJKLM''', '''XYZNOPQRSTUVW'''),
    '''I''': ('''ABCDEFGHIJKLM''', '''WXYZNOPQRSTUV'''),
    '''J''': ('''ABCDEFGHIJKLM''', '''WXYZNOPQRSTUV'''),
    '''K''': ('''ABCDEFGHIJKLM''', '''VWXYZNOPQRSTU'''),
    '''L''': ('''ABCDEFGHIJKLM''', '''VWXYZNOPQRSTU'''),
    '''M''': ('''ABCDEFGHIJKLM''', '''UVWXYZNOPQRST'''),
    '''N''': ('''ABCDEFGHIJKLM''', '''UVWXYZNOPQRST'''),
    '''O''': ('''ABCDEFGHIJKLM''', '''TUVWXYZNOPQRS'''),
    '''P''': ('''ABCDEFGHIJKLM''', '''TUVWXYZNOPQRS'''),
    '''Q''': ('''ABCDEFGHIJKLM''', '''STUVWXYZNOPQR'''),
    '''R''': ('''ABCDEFGHIJKLM''', '''STUVWXYZNOPQR'''),
    '''S''': ('''ABCDEFGHIJKLM''', '''RSTUVWXYZNOPQ'''),
    '''T''': ('''ABCDEFGHIJKLM''', '''RSTUVWXYZNOPQ'''),
    '''U''': ('''ABCDEFGHIJKLM''', '''QRSTUVWXYZNOP'''),
    '''V''': ('''ABCDEFGHIJKLM''', '''QRSTUVWXYZNOP'''),
    '''W''': ('''ABCDEFGHIJKLM''', '''PQRSTUVWXYZNO'''),
    '''X''': ('''ABCDEFGHIJKLM''', '''PQRSTUVWXYZNO'''),
    '''Y''': ('''ABCDEFGHIJKLM''', '''OPQRSTUVWXYZN'''),
    '''Z''': ('''ABCDEFGHIJKLM''', '''OPQRSTUVWXYZN'''),
}

def 		SCREAMING_SNAKE_CASE      (					lowerCAmelCase__     :	str)			->						list[tuple[str, str]]:

     '''simple docstring'''




     return [alphabet[char] for char in key.upper()]

def 		SCREAMING_SNAKE_CASE      (					lowerCAmelCase__     :	str       ,  lowerCAmelCase__     :	str)			->						str:

     '''simple docstring'''




     _lowercase							:      Optional[int]  						=							''
     _lowercase							:      List[str]  						=							0
     _lowercase							:      Optional[Any]  						=							generate_table(lowerCAmelCase__)
     for char in words.upper():
          cipher += get_opponent(table[count]       ,  lowerCAmelCase__)
          _lowercase							:      Dict  						=							(count + 1) % len(lowerCAmelCase__)
     return cipher

def 		SCREAMING_SNAKE_CASE      (					lowerCAmelCase__     :	str       ,  lowerCAmelCase__     :	str)			->						str:

     '''simple docstring'''




     return encrypt(lowerCAmelCase__       ,  lowerCAmelCase__)

def 		SCREAMING_SNAKE_CASE      (					lowerCAmelCase__     :	tuple[str, str]       ,  lowerCAmelCase__     :	str)			->						tuple[int, int]:

     '''simple docstring'''




     _lowercase							:      Optional[Any]  						=							0 if char in table[0] else 1
     _lowercase							:      Tuple  						=							table[row].index(lowerCAmelCase__)
     return row, col

def 		SCREAMING_SNAKE_CASE      (					lowerCAmelCase__     :	tuple[str, str]       ,  lowerCAmelCase__     :	str)			->						str:

     '''simple docstring'''




     _lowercase						, _lowercase							:      str  						=							get_position(lowerCAmelCase__       ,  char.upper())
     if row == 1:
          return table[0][col]
     else:
          return table[1][col] if row == 0 else char


if __name__ == "__main__":
    import doctest

    doctest.testmod()  # Fist ensure that all our tests are passing...
    A						    =							input('''Enter key: ''').strip()
    A						    =							input('''Enter text to encrypt: ''').strip()
    A						    =							encrypt(key, text)

    print(F"""Encrypted: {cipher_text}""")
    print(F"""Decrypted with key: {decrypt(key, cipher_text)}""")