





"""simple docstring"""


from collections import OrderedDict
from typing import Any, Mapping, Optional

from ... import PreTrainedTokenizer
from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig, OnnxConfigWithPast, OnnxSeqaSeqConfigWithPast
from ...onnx.utils import compute_effective_axis_dimension
from ...utils import TensorType, is_torch_available, logging


a__       :  List[str]       		=					logging.get_logger(__name__)

a__       :  str       		=					{
    """google/bigbird-pegasus-large-arxiv""": (
        """https://huggingface.co/google/bigbird-pegasus-large-arxiv/resolve/main/config.json"""
    ),
    """google/bigbird-pegasus-large-pubmed""": (
        """https://huggingface.co/google/bigbird-pegasus-large-pubmed/resolve/main/config.json"""
    ),
    """google/bigbird-pegasus-large-bigpatent""": (
        """https://huggingface.co/google/bigbird-pegasus-large-bigpatent/resolve/main/config.json"""
    ),
    # See all BigBirdPegasus models at https://huggingface.co/models?filter=bigbird_pegasus
}



class   lowercase_					(  __lowerCAmelCase				):
       snake_case__					:				Union[str, Any]									=  """bigbird_pegasus"""
       snake_case__					:				Dict									=  ["""past_key_values"""]
       snake_case__					:				Optional[int]									=  {
           """num_attention_heads""": """encoder_attention_heads""",
           """hidden_size""": """d_model""",
           """attention_probs_dropout_prob""": """attention_dropout""",
       }

       def __init__(      self ,       __SCREAMING_SNAKE_CASE=9_6103 ,       __SCREAMING_SNAKE_CASE=4096 ,       __SCREAMING_SNAKE_CASE=16 ,       __SCREAMING_SNAKE_CASE=4096 ,       __SCREAMING_SNAKE_CASE=16 ,       __SCREAMING_SNAKE_CASE=16 ,       __SCREAMING_SNAKE_CASE=4096 ,       __SCREAMING_SNAKE_CASE=16 ,       __SCREAMING_SNAKE_CASE=0.0 ,       __SCREAMING_SNAKE_CASE=0.0 ,       __SCREAMING_SNAKE_CASE=True ,       __SCREAMING_SNAKE_CASE=True ,       __SCREAMING_SNAKE_CASE="gelu_new" ,       __SCREAMING_SNAKE_CASE=1024 ,       __SCREAMING_SNAKE_CASE=0.1 ,       __SCREAMING_SNAKE_CASE=0.0 ,       __SCREAMING_SNAKE_CASE=0.0 ,       __SCREAMING_SNAKE_CASE=0.02 ,       __SCREAMING_SNAKE_CASE=2 ,       __SCREAMING_SNAKE_CASE=0.0 ,       __SCREAMING_SNAKE_CASE=True ,       __SCREAMING_SNAKE_CASE=0 ,       __SCREAMING_SNAKE_CASE=2 ,       __SCREAMING_SNAKE_CASE=1 ,       __SCREAMING_SNAKE_CASE="block_sparse" ,       __SCREAMING_SNAKE_CASE=64 ,       __SCREAMING_SNAKE_CASE=3 ,       __SCREAMING_SNAKE_CASE=False ,       **__SCREAMING_SNAKE_CASE ,       ):






        '''simple docstring'''

        snake_case__     				=					vocab_size
        snake_case__     				=					max_position_embeddings
        snake_case__     				=					d_model
        snake_case__     				=					encoder_ffn_dim
        snake_case__     				=					encoder_layers
        snake_case__     				=					encoder_attention_heads
        snake_case__     				=					decoder_ffn_dim
        snake_case__     				=					decoder_layers
        snake_case__     				=					decoder_attention_heads
        snake_case__     				=					dropout
        snake_case__     				=					attention_dropout
        snake_case__     				=					activation_dropout
        snake_case__     				=					activation_function
        snake_case__     				=					init_std
        snake_case__     				=					encoder_layerdrop
        snake_case__     				=					decoder_layerdrop
        snake_case__     				=					classifier_dropout
        snake_case__     				=					use_cache
        snake_case__     				=					encoder_layers
        snake_case__     				=					scale_embedding  # scale factor will be sqrt(d_model) if True

        # extra config
        snake_case__     				=					attention_type
        snake_case__     				=					block_size
        snake_case__     				=					num_random_blocks
        snake_case__     				=					use_bias

        super().__init__(
            pad_token_id=__SCREAMING_SNAKE_CASE ,       bos_token_id=__SCREAMING_SNAKE_CASE ,       eos_token_id=__SCREAMING_SNAKE_CASE ,       is_encoder_decoder=__SCREAMING_SNAKE_CASE ,       decoder_start_token_id=__SCREAMING_SNAKE_CASE ,       **__SCREAMING_SNAKE_CASE ,       )



class   lowercase_					(  __lowerCAmelCase				):

       @property
       def 		_SCREAMING_SNAKE_CASE(      self  ):






        '''simple docstring'''

        if self.task in ["default", "seq2seq-lm"]:
         snake_case__     				=					OrderedDict(
             [
                 ("input_ids", {0: "batch", 1: "encoder_sequence"}),
                 ("attention_mask", {0: "batch", 1: "encoder_sequence"}),
             ]  )

         if self.use_past:
          snake_case__     				=					{0: "batch"}
          snake_case__     				=					{0: "batch", 1: "past_decoder_sequence + sequence"}
         else:
          snake_case__     				=					{0: "batch", 1: "decoder_sequence"}
          snake_case__     				=					{0: "batch", 1: "decoder_sequence"}

         if self.use_past:
          self.fill_with_past_key_values_(__SCREAMING_SNAKE_CASE ,       direction="inputs"  )
        elif self.task == "causal-lm":
         # TODO: figure this case out.
         snake_case__     				=					OrderedDict(
             [
                 ("input_ids", {0: "batch", 1: "encoder_sequence"}),
                 ("attention_mask", {0: "batch", 1: "encoder_sequence"}),
             ]  )
         if self.use_past:
          snake_case__				, snake_case__     				=					self.num_layers
          for i in range(__SCREAMING_SNAKE_CASE  ):
           snake_case__     				=					{0: "batch", 2: "past_sequence + sequence"}
           snake_case__     				=					{0: "batch", 2: "past_sequence + sequence"}
        else:
         snake_case__     				=					OrderedDict(
             [
                 ("input_ids", {0: "batch", 1: "encoder_sequence"}),
                 ("attention_mask", {0: "batch", 1: "encoder_sequence"}),
                 ("decoder_input_ids", {0: "batch", 1: "decoder_sequence"}),
                 ("decoder_attention_mask", {0: "batch", 1: "decoder_sequence"}),
             ]  )

        return common_inputs

       @property
       def 		_SCREAMING_SNAKE_CASE(      self  ):






        '''simple docstring'''

        if self.task in ["default", "seq2seq-lm"]:
         snake_case__     				=					super().outputs
        else:
         snake_case__     				=					super(__SCREAMING_SNAKE_CASE ,       self  ).outputs
         if self.use_past:
          snake_case__				, snake_case__     				=					self.num_layers
          for i in range(__SCREAMING_SNAKE_CASE  ):
           snake_case__     				=					{0: "batch", 2: "past_sequence + sequence"}
           snake_case__     				=					{0: "batch", 2: "past_sequence + sequence"}
        return common_outputs

       def 		_SCREAMING_SNAKE_CASE(      self ,       __SCREAMING_SNAKE_CASE ,       __SCREAMING_SNAKE_CASE = -1 ,       __SCREAMING_SNAKE_CASE = -1 ,       __SCREAMING_SNAKE_CASE = False ,       __SCREAMING_SNAKE_CASE = None ,       ):






        '''simple docstring'''

        snake_case__     				=					self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
            __SCREAMING_SNAKE_CASE ,       __SCREAMING_SNAKE_CASE ,       __SCREAMING_SNAKE_CASE ,       __SCREAMING_SNAKE_CASE ,       __SCREAMING_SNAKE_CASE  )

        # Generate decoder inputs
        snake_case__     				=					seq_length if not self.use_past else 1
        snake_case__     				=					self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
            __SCREAMING_SNAKE_CASE ,       __SCREAMING_SNAKE_CASE ,       __SCREAMING_SNAKE_CASE ,       __SCREAMING_SNAKE_CASE ,       __SCREAMING_SNAKE_CASE  )
        snake_case__     				=					{F"decoder_{name}": tensor for name, tensor in decoder_inputs.items()}
        snake_case__     				=					dict(**__SCREAMING_SNAKE_CASE ,       **__SCREAMING_SNAKE_CASE  )

        if self.use_past:
         if not is_torch_available():
          raise ValueError("Cannot generate dummy past_keys inputs without PyTorch installed."  )
         else:
          import torch
         snake_case__				, snake_case__     				=					common_inputs["input_ids"].shape
         snake_case__     				=					common_inputs["decoder_input_ids"].shape[1]
         snake_case__				, snake_case__     				=					self.num_attention_heads
         snake_case__     				=					(
             batch,
             num_encoder_attention_heads,
             encoder_seq_length,
             self._config.hidden_size // num_encoder_attention_heads,
         )
         snake_case__     				=					decoder_seq_length + 3
         snake_case__     				=					(
             batch,
             num_decoder_attention_heads,
             decoder_past_length,
             self._config.hidden_size // num_decoder_attention_heads,
         )

         snake_case__     				=					torch.cat(
             [common_inputs["decoder_attention_mask"], torch.ones(__SCREAMING_SNAKE_CASE ,       __SCREAMING_SNAKE_CASE  )] ,       dim=1  )

         snake_case__     				=					[]
         # If the number of encoder and decoder layers are present in the model configuration, both are considered
         snake_case__				, snake_case__     				=					self.num_layers
         snake_case__     				=					min(__SCREAMING_SNAKE_CASE ,       __SCREAMING_SNAKE_CASE  )
         snake_case__     				=					max(__SCREAMING_SNAKE_CASE ,       __SCREAMING_SNAKE_CASE  ) - min_num_layers
         snake_case__     				=					"encoder" if num_encoder_layers > num_decoder_layers else "decoder"

         for _ in range(__SCREAMING_SNAKE_CASE  ):
          common_inputs["past_key_values"].append(
              (
                  torch.zeros(__SCREAMING_SNAKE_CASE  ),
                  torch.zeros(__SCREAMING_SNAKE_CASE  ),
                  torch.zeros(__SCREAMING_SNAKE_CASE  ),
                  torch.zeros(__SCREAMING_SNAKE_CASE  ),
              )  )
         # TODO: test this.
         snake_case__     				=					encoder_shape if remaining_side_name == "encoder" else decoder_shape
         for _ in range(__SCREAMING_SNAKE_CASE ,       __SCREAMING_SNAKE_CASE  ):
          common_inputs["past_key_values"].append((torch.zeros(__SCREAMING_SNAKE_CASE  ), torch.zeros(__SCREAMING_SNAKE_CASE  ))  )
        return common_inputs

       def 		_SCREAMING_SNAKE_CASE(      self ,       __SCREAMING_SNAKE_CASE ,       __SCREAMING_SNAKE_CASE = -1 ,       __SCREAMING_SNAKE_CASE = -1 ,       __SCREAMING_SNAKE_CASE = False ,       __SCREAMING_SNAKE_CASE = None ,       ):






        '''simple docstring'''

        snake_case__     				=					self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
            __SCREAMING_SNAKE_CASE ,       __SCREAMING_SNAKE_CASE ,       __SCREAMING_SNAKE_CASE ,       __SCREAMING_SNAKE_CASE ,       __SCREAMING_SNAKE_CASE  )

        if self.use_past:
         if not is_torch_available():
          raise ValueError("Cannot generate dummy past_keys inputs without PyTorch installed."  )
         else:
          import torch
         snake_case__				, snake_case__     				=					common_inputs["input_ids"].shape
         # Not using the same length for past_key_values
         snake_case__     				=					seqlen + 2
         snake_case__				, snake_case__     				=					self.num_layers
         snake_case__				, snake_case__     				=					self.num_attention_heads
         snake_case__     				=					(
             batch,
             num_encoder_attention_heads,
             past_key_values_length,
             self._config.hidden_size // num_encoder_attention_heads,
         )

         snake_case__     				=					common_inputs["attention_mask"].dtype
         snake_case__     				=					torch.cat(
             [common_inputs["attention_mask"], torch.ones(__SCREAMING_SNAKE_CASE ,       __SCREAMING_SNAKE_CASE ,       dtype=__SCREAMING_SNAKE_CASE  )] ,       dim=1  )
         snake_case__     				=					[
             (torch.zeros(__SCREAMING_SNAKE_CASE  ), torch.zeros(__SCREAMING_SNAKE_CASE  )) for _ in range(__SCREAMING_SNAKE_CASE  )
         ]
        return common_inputs

       def 		_SCREAMING_SNAKE_CASE(      self ,       __SCREAMING_SNAKE_CASE ,       __SCREAMING_SNAKE_CASE = -1 ,       __SCREAMING_SNAKE_CASE = -1 ,       __SCREAMING_SNAKE_CASE = False ,       __SCREAMING_SNAKE_CASE = None ,       ):






        '''simple docstring'''

        snake_case__     				=					compute_effective_axis_dimension(
            __SCREAMING_SNAKE_CASE ,       fixed_dimension=OnnxConfig.default_fixed_batch ,       num_token_to_add=0  )

        # If dynamic axis (-1) we forward with a fixed dimension of 8 tokens to avoid optimizations made by ONNX
        snake_case__     				=					tokenizer.num_special_tokens_to_add(__SCREAMING_SNAKE_CASE  )
        snake_case__     				=					compute_effective_axis_dimension(
            __SCREAMING_SNAKE_CASE ,       fixed_dimension=OnnxConfig.default_fixed_sequence ,       num_token_to_add=__SCREAMING_SNAKE_CASE  )

        # Generate dummy inputs according to compute batch and sequence
        snake_case__     				=					[" ".join([tokenizer.unk_token]  ) * seq_length] * batch_size
        snake_case__     				=					dict(tokenizer(__SCREAMING_SNAKE_CASE ,       return_tensors=__SCREAMING_SNAKE_CASE  )  )
        return common_inputs

       def 		_SCREAMING_SNAKE_CASE(      self ,       __SCREAMING_SNAKE_CASE ,       __SCREAMING_SNAKE_CASE = -1 ,       __SCREAMING_SNAKE_CASE = -1 ,       __SCREAMING_SNAKE_CASE = False ,       __SCREAMING_SNAKE_CASE = None ,       ):






        '''simple docstring'''

        if self.task in ["default", "seq2seq-lm"]:
         snake_case__     				=					self._generate_dummy_inputs_for_default_and_seqaseq_lm(
             __SCREAMING_SNAKE_CASE ,       batch_size=__SCREAMING_SNAKE_CASE ,       seq_length=__SCREAMING_SNAKE_CASE ,       is_pair=__SCREAMING_SNAKE_CASE ,       framework=__SCREAMING_SNAKE_CASE  )

        elif self.task == "causal-lm":
         snake_case__     				=					self._generate_dummy_inputs_for_causal_lm(
             __SCREAMING_SNAKE_CASE ,       batch_size=__SCREAMING_SNAKE_CASE ,       seq_length=__SCREAMING_SNAKE_CASE ,       is_pair=__SCREAMING_SNAKE_CASE ,       framework=__SCREAMING_SNAKE_CASE  )
        else:
         snake_case__     				=					self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
             __SCREAMING_SNAKE_CASE ,       batch_size=__SCREAMING_SNAKE_CASE ,       seq_length=__SCREAMING_SNAKE_CASE ,       is_pair=__SCREAMING_SNAKE_CASE ,       framework=__SCREAMING_SNAKE_CASE  )

        return common_inputs

       def 		_SCREAMING_SNAKE_CASE(      self ,       __SCREAMING_SNAKE_CASE ,       __SCREAMING_SNAKE_CASE ,       __SCREAMING_SNAKE_CASE ,       __SCREAMING_SNAKE_CASE  ):






        '''simple docstring'''

        if self.task in ["default", "seq2seq-lm"]:
         snake_case__     				=					super()._flatten_past_key_values_(__SCREAMING_SNAKE_CASE ,       __SCREAMING_SNAKE_CASE ,       __SCREAMING_SNAKE_CASE ,       __SCREAMING_SNAKE_CASE  )
        else:
         snake_case__     				=					super(__SCREAMING_SNAKE_CASE ,       self  )._flatten_past_key_values_(
             __SCREAMING_SNAKE_CASE ,       __SCREAMING_SNAKE_CASE ,       __SCREAMING_SNAKE_CASE ,       __SCREAMING_SNAKE_CASE  )








"""simple docstring"""


a__       :  Optional[Any]       		=					{
    """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 				a__      (	_UpperCAmelCase						)     ->	list[tuple[str, str]]:

 '''simple docstring'''






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





def 				a__      (	_UpperCAmelCase						,  _UpperCAmelCase						)     ->	str:

 '''simple docstring'''






 snake_case__     				=					""
 snake_case__     				=					0
 snake_case__     				=					generate_table(_UpperCAmelCase						)
 for char in words.upper():
  cipher += get_opponent(table[count]						,  _UpperCAmelCase						)
  snake_case__     				=					(count + 1) % len(_UpperCAmelCase						)
 return cipher





def 				a__      (	_UpperCAmelCase						,  _UpperCAmelCase						)     ->	str:

 '''simple docstring'''






 return encrypt(_UpperCAmelCase						,  _UpperCAmelCase						)





def 				a__      (	_UpperCAmelCase						,  _UpperCAmelCase						)     ->	tuple[int, int]:

 '''simple docstring'''






 snake_case__     				=					0 if char in table[0] else 1
 snake_case__     				=					table[row].index(_UpperCAmelCase						)
 return row, col





def 				a__      (	_UpperCAmelCase						,  _UpperCAmelCase						)     ->	str:

 '''simple docstring'''






 snake_case__				, snake_case__     				=					get_position(_UpperCAmelCase						,  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__       :  int       		=					input("""Enter key: """).strip()
   a__       :  Optional[int]       		=					input("""Enter text to encrypt: """).strip()
   a__       :  Dict       		=					encrypt(key, text)

   print(f'''Encrypted: {cipher_text}''')
   print(f'''Decrypted with key: {decrypt(key, cipher_text)}''')

