



'''simple docstring'''





import collections
import inspect
import unittest

from transformers import SwinConfig
from transformers.testing_utils import require_torch, require_vision, slow, torch_device
from transformers.utils import cached_property, is_torch_available, is_vision_available

from ...test_backbone_common import BackboneTesterMixin
from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, _config_zero_init, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
      import torch
      from torch import nn

      from transformers import SwinBackbone, SwinForImageClassification, SwinForMaskedImageModeling, SwinModel
      from transformers.models.swin.modeling_swin import SWIN_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
      from PIL import Image

      from transformers import AutoImageProcessor





class 							lowerCAmelCase_		:





    def __init__(    self    :    Tuple,    _snake_case    :    Union[str, Any],    _snake_case    :    str=13,    _snake_case    :    Union[str, Any]=32,    _snake_case    :    List[str]=2,    _snake_case    :    Optional[int]=3,    _snake_case    :    str=16,    _snake_case    :    Any=[1, 2, 1],    _snake_case    :    Optional[int]=[2, 2, 4],    _snake_case    :    Optional[Any]=2,    _snake_case    :    Dict=2.0,    _snake_case    :    List[str]=True,    _snake_case    :    Union[str, Any]=0.0,    _snake_case    :    Any=0.0,    _snake_case    :    int=0.1,    _snake_case    :    Union[str, Any]="gelu",    _snake_case    :    List[str]=False,    _snake_case    :    Any=True,    _snake_case    :    Dict=0.02,    _snake_case    :    Dict=1E-5,    _snake_case    :    Any=True,    _snake_case    :    Tuple=None,    _snake_case    :    Dict=True,    _snake_case    :    Tuple=10,    _snake_case    :    List[str]=8,    _snake_case    :    Optional[Any]=["stage1", "stage2"],    _snake_case    :    Tuple=[1, 2],    ):



       '''simple docstring'''







       snake_case   :							List[str]						  =parent
       snake_case   :							Any						  =batch_size
       snake_case   :							List[str]						  =image_size
       snake_case   :							Tuple						  =patch_size
       snake_case   :							Tuple						  =num_channels
       snake_case   :							str						  =embed_dim
       snake_case   :							Optional[Any]						  =depths
       snake_case   :							str						  =num_heads
       snake_case   :							Tuple						  =window_size
       snake_case   :							Any						  =mlp_ratio
       snake_case   :							List[Any]						  =qkv_bias
       snake_case   :							Dict						  =hidden_dropout_prob
       snake_case   :							str						  =attention_probs_dropout_prob
       snake_case   :							List[str]						  =drop_path_rate
       snake_case   :							Tuple						  =hidden_act
       snake_case   :							Tuple						  =use_absolute_embeddings
       snake_case   :							List[Any]						  =patch_norm
       snake_case   :							Any						  =layer_norm_eps
       snake_case   :							Union[str, Any]						  =initializer_range
       snake_case   :							int						  =is_training
       snake_case   :							Dict						  =scope
       snake_case   :							Tuple						  =use_labels
       snake_case   :							Dict						  =type_sequence_label_size
       snake_case   :							Optional[Any]						  =encoder_stride
       snake_case   :							Union[str, Any]						  =out_features
       snake_case   :							Optional[Any]						  =out_indices





    def 					__snake_case       (    self    :    Tuple     ):



       '''simple docstring'''







       snake_case   :							Optional[Any]						  =floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]     )

       snake_case   :							List[Any]						  =None
       if self.use_labels:
          snake_case   :							str						  =ids_tensor([self.batch_size],    self.type_sequence_label_size     )

       snake_case   :							str						  =self.get_config()

       return config, pixel_values, labels





    def 					__snake_case       (    self    :    Optional[Any]     ):



       '''simple docstring'''







       return SwinConfig(
           image_size=self.image_size,    patch_size=self.patch_size,    num_channels=self.num_channels,    embed_dim=self.embed_dim,    depths=self.depths,    num_heads=self.num_heads,    window_size=self.window_size,    mlp_ratio=self.mlp_ratio,    qkv_bias=self.qkv_bias,    hidden_dropout_prob=self.hidden_dropout_prob,    attention_probs_dropout_prob=self.attention_probs_dropout_prob,    drop_path_rate=self.drop_path_rate,    hidden_act=self.hidden_act,    use_absolute_embeddings=self.use_absolute_embeddings,    path_norm=self.patch_norm,    layer_norm_eps=self.layer_norm_eps,    initializer_range=self.initializer_range,    encoder_stride=self.encoder_stride,    out_features=self.out_features,    out_indices=self.out_indices,    )





    def 					__snake_case       (    self    :    Optional[int],    _snake_case    :    int,    _snake_case    :    List[str],    _snake_case    :    List[Any]     ):



       '''simple docstring'''







       snake_case   :							Any						  =SwinModel(config=_snake_case     )
       model.to(_snake_case     )
       model.eval()
       snake_case   :							Dict						  =model(_snake_case     )

       snake_case   :							List[Any]						  =((config.image_size // config.patch_size) ** 2) // (4 ** (len(config.depths     ) - 1))
       snake_case   :							Dict						  =int(config.embed_dim * 2 ** (len(config.depths     ) - 1)     )

       self.parent.assertEqual(result.last_hidden_state.shape,    (self.batch_size, expected_seq_len, expected_dim)     )





    def 					__snake_case       (    self    :    Dict,    _snake_case    :    List[Any],    _snake_case    :    Optional[Any],    _snake_case    :    Any     ):



       '''simple docstring'''







       snake_case   :							Optional[int]						  =SwinBackbone(config=_snake_case     )
       model.to(_snake_case     )
       model.eval()
       snake_case   :							Optional[int]						  =model(_snake_case     )

       # verify hidden states
       self.parent.assertEqual(len(result.feature_maps     ),    len(config.out_features     )     )
       self.parent.assertListEqual(list(result.feature_maps[0].shape     ),    [self.batch_size, model.channels[0], 16, 16]     )

       # verify channels
       self.parent.assertEqual(len(model.channels     ),    len(config.out_features     )     )

       # verify backbone works with out_features=None
       snake_case   :							int						  =None
       snake_case   :							List[str]						  =SwinBackbone(config=_snake_case     )
       model.to(_snake_case     )
       model.eval()
       snake_case   :							Union[str, Any]						  =model(_snake_case     )

       # verify feature maps
       self.parent.assertEqual(len(result.feature_maps     ),    1     )
       self.parent.assertListEqual(list(result.feature_maps[0].shape     ),    [self.batch_size, model.channels[-1], 4, 4]     )

       # verify channels
       self.parent.assertEqual(len(model.channels     ),    1     )





    def 					__snake_case       (    self    :    str,    _snake_case    :    List[str],    _snake_case    :    int,    _snake_case    :    str     ):



       '''simple docstring'''







       snake_case   :							int						  =SwinForMaskedImageModeling(config=_snake_case     )
       model.to(_snake_case     )
       model.eval()
       snake_case   :							Union[str, Any]						  =model(_snake_case     )
       self.parent.assertEqual(
           result.logits.shape,    (self.batch_size, self.num_channels, self.image_size, self.image_size)     )

       # test greyscale images
       snake_case   :							Any						  =1
       snake_case   :							List[Any]						  =SwinForMaskedImageModeling(_snake_case     )
       model.to(_snake_case     )
       model.eval()

       snake_case   :							str						  =floats_tensor([self.batch_size, 1, self.image_size, self.image_size]     )
       snake_case   :							int						  =model(_snake_case     )
       self.parent.assertEqual(result.logits.shape,    (self.batch_size, 1, self.image_size, self.image_size)     )





    def 					__snake_case       (    self    :    List[Any],    _snake_case    :    str,    _snake_case    :    Union[str, Any],    _snake_case    :    Dict     ):



       '''simple docstring'''







       snake_case   :							List[Any]						  =self.type_sequence_label_size
       snake_case   :							Tuple						  =SwinForImageClassification(_snake_case     )
       model.to(_snake_case     )
       model.eval()
       snake_case   :							str						  =model(_snake_case,    labels=_snake_case     )
       self.parent.assertEqual(result.logits.shape,    (self.batch_size, self.type_sequence_label_size)     )

       # test greyscale images
       snake_case   :							Union[str, Any]						  =1
       snake_case   :							List[str]						  =SwinForImageClassification(_snake_case     )
       model.to(_snake_case     )
       model.eval()

       snake_case   :							Any						  =floats_tensor([self.batch_size, 1, self.image_size, self.image_size]     )
       snake_case   :							List[str]						  =model(_snake_case     )
       self.parent.assertEqual(result.logits.shape,    (self.batch_size, self.type_sequence_label_size)     )






    def 					__snake_case       (    self    :    List[Any]     ):



       '''simple docstring'''







       snake_case   :							Union[str, Any]						  =self.prepare_config_and_inputs()
       (
           (
           snake_case
       )  ,    (
           snake_case
       )  ,    (
           snake_case
       )  ,    
       )   :							List[str]						  =config_and_inputs
       snake_case   :							int						  ={'''pixel_values''': pixel_values}
       return config, inputs_dict





@require_torch
class 							lowerCAmelCase_		(	a_  ,      a_  ,      unittest.TestCase						):
    __UpperCAmelCase							=	(
        (
            SwinModel,
            SwinBackbone,
            SwinForImageClassification,
            SwinForMaskedImageModeling,
        )
        if is_torch_available()
        else ()
    )
    __UpperCAmelCase							=	(
        {'feature-extraction': SwinModel, 'image-classification': SwinForImageClassification}
        if is_torch_available()
        else {}
    )
    __UpperCAmelCase							=	True

    __UpperCAmelCase							=	False
    __UpperCAmelCase							=	False
    __UpperCAmelCase							=	False





    def 					__snake_case       (    self    :    int     ):



       '''simple docstring'''







       snake_case   :							Optional[int]						  =SwinModelTester(self     )
       snake_case   :							int						  =ConfigTester(self,    config_class=_snake_case,    embed_dim=37     )





    def 					__snake_case       (    self    :    int     ):



       '''simple docstring'''







       self.create_and_test_config_common_properties()
       self.config_tester.create_and_test_config_to_json_string()
       self.config_tester.create_and_test_config_to_json_file()
       self.config_tester.create_and_test_config_from_and_save_pretrained()
       self.config_tester.create_and_test_config_with_num_labels()
       self.config_tester.check_config_can_be_init_without_params()
       self.config_tester.check_config_arguments_init()





    def 					__snake_case       (    self    :    Union[str, Any]     ):



       '''simple docstring'''







       return





    def 					__snake_case       (    self    :    Union[str, Any]     ):



       '''simple docstring'''







       snake_case   :							Dict						  =self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_model(*_snake_case     )





    @unittest.skip(reason='''Got `CUDA error: misaligned address` with PyTorch 2.0.0.'''     )
    def 					__snake_case       (    self    :    List[Any]     ):



       '''simple docstring'''







       pass





    def 					__snake_case       (    self    :    Optional[int]     ):



       '''simple docstring'''







       super().test_training_gradient_checkpointing()





    def 					__snake_case       (    self    :    Union[str, Any]     ):



       '''simple docstring'''







       snake_case   :							Any						  =self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_backbone(*_snake_case     )





    def 					__snake_case       (    self    :    List[Any]     ):



       '''simple docstring'''







       snake_case   :							List[str]						  =self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_masked_image_modeling(*_snake_case     )





    def 					__snake_case       (    self    :    List[str]     ):



       '''simple docstring'''







       snake_case   :							List[Any]						  =self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_image_classification(*_snake_case     )





    @unittest.skip(reason='''Swin does not use inputs_embeds'''     )
    def 					__snake_case       (    self    :    Union[str, Any]     ):



       '''simple docstring'''







       pass





    @unittest.skip(reason='''Swin Transformer does not use feedforward chunking'''     )
    def 					__snake_case       (    self    :    int     ):



       '''simple docstring'''







       pass





    def 					__snake_case       (    self    :    List[Any]     ):



       '''simple docstring'''







       snake_case  ,    snake_case   :							Dict						  =self.model_tester.prepare_config_and_inputs_for_common()

       for model_class in self.all_model_classes:
          snake_case   :							Dict						  =model_class(_snake_case     )
          self.assertIsInstance(model.get_input_embeddings(),    (nn.Module)     )
          snake_case   :							str						  =model.get_output_embeddings()
          self.assertTrue(x is None or isinstance(_snake_case,    nn.Linear     )     )





    def 					__snake_case       (    self    :    Optional[Any]     ):



       '''simple docstring'''







       snake_case  ,    snake_case   :							Optional[int]						  =self.model_tester.prepare_config_and_inputs_for_common()

       for model_class in self.all_model_classes:
          snake_case   :							Optional[int]						  =model_class(_snake_case     )
          snake_case   :							List[str]						  =inspect.signature(model.forward     )
          # signature.parameters is an OrderedDict => so arg_names order is deterministic
          snake_case   :							str						  =[*signature.parameters.keys()]

          snake_case   :							Union[str, Any]						  =['''pixel_values''']
          self.assertListEqual(arg_names[:1],    _snake_case     )





    def 					__snake_case       (    self    :    Any     ):



       '''simple docstring'''







       snake_case  ,    snake_case   :							str						  =self.model_tester.prepare_config_and_inputs_for_common()
       snake_case   :							int						  =True

       for model_class in self.all_model_classes:
          snake_case   :							Optional[int]						  =True
          snake_case   :							Optional[int]						  =False
          snake_case   :							Optional[int]						  =True
          snake_case   :							Union[str, Any]						  =model_class(_snake_case     )
          model.to(_snake_case     )
          model.eval()
          with torch.no_grad():
             snake_case   :							Tuple						  =model(**self._prepare_for_class(_snake_case,    _snake_case     )     )
          snake_case   :							Optional[int]						  =outputs.attentions
          snake_case   :							List[str]						  =len(self.model_tester.depths     )
          self.assertEqual(len(_snake_case     ),    _snake_case     )

          # check that output_attentions also work using config
          del inputs_dict["output_attentions"]
          snake_case   :							Tuple						  =True
          snake_case   :							int						  =config.window_size**2
          snake_case   :							List[Any]						  =model_class(_snake_case     )
          model.to(_snake_case     )
          model.eval()
          with torch.no_grad():
             snake_case   :							Optional[Any]						  =model(**self._prepare_for_class(_snake_case,    _snake_case     )     )
          snake_case   :							Union[str, Any]						  =outputs.attentions
          self.assertEqual(len(_snake_case     ),    _snake_case     )

          self.assertListEqual(
              list(attentions[0].shape[-3:]     ),    [self.model_tester.num_heads[0], window_size_squared, window_size_squared],    )
          snake_case   :							str						  =len(_snake_case     )

          # Check attention is always last and order is fine
          snake_case   :							Dict						  =True
          snake_case   :							Any						  =True
          snake_case   :							Optional[Any]						  =model_class(_snake_case     )
          model.to(_snake_case     )
          model.eval()
          with torch.no_grad():
             snake_case   :							Optional[int]						  =model(**self._prepare_for_class(_snake_case,    _snake_case     )     )

          # also another +1 for reshaped_hidden_states
          snake_case   :							Union[str, Any]						  =1 if model_class.__name__ == '''SwinBackbone''' else 2
          self.assertEqual(out_len + added_hidden_states,    len(_snake_case     )     )

          snake_case   :							Tuple						  =outputs.attentions

          self.assertEqual(len(_snake_case     ),    _snake_case     )

          self.assertListEqual(
              list(self_attentions[0].shape[-3:]     ),    [self.model_tester.num_heads[0], window_size_squared, window_size_squared],    )





    def 					__snake_case       (    self    :    Any,    _snake_case    :    Tuple,    _snake_case    :    List[Any],    _snake_case    :    List[str],    _snake_case    :    Optional[int]     ):



       '''simple docstring'''







       snake_case   :							Optional[int]						  =model_class(_snake_case     )
       model.to(_snake_case     )
       model.eval()

       with torch.no_grad():
          snake_case   :							List[str]						  =model(**self._prepare_for_class(_snake_case,    _snake_case     )     )

       snake_case   :							int						  =outputs.hidden_states

       snake_case   :							Optional[int]						  =getattr(
           self.model_tester,    '''expected_num_hidden_layers''',    len(self.model_tester.depths     ) + 1     )
       self.assertEqual(len(_snake_case     ),    _snake_case     )

       # Swin has a different seq_length
       snake_case   :							Union[str, Any]						  =(
           config.patch_size
           if isinstance(config.patch_size,    collections.abc.Iterable     )
           else (config.patch_size, config.patch_size)
       )

       snake_case   :							Tuple						  =(image_size[1] // patch_size[1]) * (image_size[0] // patch_size[0])

       self.assertListEqual(
           list(hidden_states[0].shape[-2:]     ),    [num_patches, self.model_tester.embed_dim],    )

       if not model_class.__name__ == "SwinBackbone":
          snake_case   :							List[str]						  =outputs.reshaped_hidden_states
          self.assertEqual(len(_snake_case     ),    _snake_case     )

          snake_case  ,    snake_case  ,    snake_case  ,    snake_case   :							int						  =reshaped_hidden_states[0].shape
          snake_case   :							str						  =(
              reshaped_hidden_states[0].view(_snake_case,    _snake_case,    height * width     ).permute(0,    2,    1     )
          )
          self.assertListEqual(
              list(reshaped_hidden_states.shape[-2:]     ),    [num_patches, self.model_tester.embed_dim],    )





    def 					__snake_case       (    self    :    List[str]     ):



       '''simple docstring'''







       snake_case  ,    snake_case   :							str						  =self.model_tester.prepare_config_and_inputs_for_common()

       snake_case   :							Optional[Any]						  =(
           self.model_tester.image_size
           if isinstance(self.model_tester.image_size,    collections.abc.Iterable     )
           else (self.model_tester.image_size, self.model_tester.image_size)
       )

       for model_class in self.all_model_classes:
          snake_case   :							int						  =True
          self.check_hidden_states_output(_snake_case,    _snake_case,    _snake_case,    _snake_case     )

          # check that output_hidden_states also work using config
          del inputs_dict["output_hidden_states"]
          snake_case   :							str						  =True

          self.check_hidden_states_output(_snake_case,    _snake_case,    _snake_case,    _snake_case     )





    def 					__snake_case       (    self    :    Dict     ):



       '''simple docstring'''







       snake_case  ,    snake_case   :							str						  =self.model_tester.prepare_config_and_inputs_for_common()
       snake_case   :							Union[str, Any]						  =3

       snake_case   :							Optional[Any]						  =(
           self.model_tester.image_size
           if isinstance(self.model_tester.image_size,    collections.abc.Iterable     )
           else (self.model_tester.image_size, self.model_tester.image_size)
       )
       snake_case   :							Optional[int]						  =(
           config.patch_size
           if isinstance(config.patch_size,    collections.abc.Iterable     )
           else (config.patch_size, config.patch_size)
       )

       snake_case   :							Any						  =image_size[0] + patch_size[0] - (image_size[0] % patch_size[0])
       snake_case   :							Union[str, Any]						  =image_size[1] + patch_size[1] - (image_size[1] % patch_size[1])

       for model_class in self.all_model_classes:
          snake_case   :							List[str]						  =True
          self.check_hidden_states_output(_snake_case,    _snake_case,    _snake_case,    (padded_height, padded_width)     )

          # check that output_hidden_states also work using config
          del inputs_dict["output_hidden_states"]
          snake_case   :							Union[str, Any]						  =True
          self.check_hidden_states_output(_snake_case,    _snake_case,    _snake_case,    (padded_height, padded_width)     )





    @slow
    def 					__snake_case       (    self    :    Optional[int]     ):



       '''simple docstring'''







       for model_name in SWIN_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
          snake_case   :							str						  =SwinModel.from_pretrained(_snake_case     )
          self.assertIsNotNone(_snake_case     )






    def 					__snake_case       (    self    :    Optional[Any]     ):



       '''simple docstring'''







       snake_case  ,    snake_case   :							Tuple						  =self.model_tester.prepare_config_and_inputs_for_common()

       snake_case   :							Dict						  =_config_zero_init(_snake_case     )
       for model_class in self.all_model_classes:
          snake_case   :							List[str]						  =model_class(config=_snake_case     )
          for name, param in model.named_parameters():
             if "embeddings" not in name and param.requires_grad:
                self.assertIn(
                    ((param.data.mean() * 1E9).round() / 1E9).item(),    [0.0, 1.0],    msg=f'''Parameter {name} of model {model_class} seems not properly initialized''',    )





@require_vision
@require_torch
class 							lowerCAmelCase_		(	unittest.TestCase						):





    @cached_property
    def 					__snake_case       (    self    :    Optional[Any]     ):



       '''simple docstring'''







       return (
           AutoImageProcessor.from_pretrained('''microsoft/swin-tiny-patch4-window7-224'''     )
           if is_vision_available()
           else None
       )






    @slow
    def 					__snake_case       (    self    :    int     ):



       '''simple docstring'''







       snake_case   :							Dict						  =SwinForImageClassification.from_pretrained('''microsoft/swin-tiny-patch4-window7-224'''     ).to(_snake_case     )
       snake_case   :							Union[str, Any]						  =self.default_image_processor

       snake_case   :							Union[str, Any]						  =Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''     )
       snake_case   :							int						  =image_processor(images=_snake_case,    return_tensors='''pt'''     ).to(_snake_case     )

       # forward pass
       with torch.no_grad():
          snake_case   :							Any						  =model(**_snake_case     )

       # verify the logits
       snake_case   :							Dict						  =torch.Size((1, 1_000)     )
       self.assertEqual(outputs.logits.shape,    _snake_case     )
       snake_case   :							int						  =torch.tensor([-0.0948, -0.6454, -0.0921]     ).to(_snake_case     )
       self.assertTrue(torch.allclose(outputs.logits[0, :3],    _snake_case,    atol=1E-4     )     )





@require_torch
class 							lowerCAmelCase_		(	unittest.TestCase  ,      a_						):
    __UpperCAmelCase							=	(SwinBackbone,) if is_torch_available() else ()
    __UpperCAmelCase							=	SwinConfig





    def 					__snake_case       (    self    :    Dict     ):



       '''simple docstring'''







       snake_case   :							Optional[Any]						  =SwinModelTester(self     )










'''simple docstring'''





from __future__ import annotations

import random
import string





class 							lowerCAmelCase_		:





    def __init__(    self    :    Union[str, Any],    _snake_case    :    str | None = None     ):



       '''simple docstring'''







       snake_case   :							Optional[int]						  =passcode or self.__passcode_creator()
       snake_case   :							List[str]						  =self.__make_key_list()
       snake_case   :							Dict						  =self.__make_shift_key()





    def __str__(    self    :    List[Any]     ):



       '''simple docstring'''







       return "".join(self.__passcode     )





    def 					__snake_case       (    self    :    int,    _snake_case    :    list[int]     ):



       '''simple docstring'''







       for i in range(1,    len(_snake_case     ),    2     ):
          iterlist[i] *= -1
       return iterlist





    def 					__snake_case       (    self    :    Optional[int]     ):



       '''simple docstring'''







       snake_case   :							int						  =string.ascii_letters + string.digits
       snake_case   :							Union[str, Any]						  =[random.choice(_snake_case     ) for _ in range(random.randint(10,    20     )     )]
       return password





    def 					__snake_case       (    self    :    Optional[int]     ):



       '''simple docstring'''







       snake_case   :							Dict						  =(
           string.ascii_letters + string.digits + string.punctuation + ''' \t\n'''
       )

       snake_case   :							Any						  =[]

       # creates points known as breakpoints to break the key_list_options at those
       # points and pivot each substring
       snake_case   :							Optional[int]						  =sorted(set(self.__passcode     )     )
       snake_case   :							list[str]						  =[]

       # algorithm for creating a new shuffled list, keys_l, out of key_list_options
       for i in key_list_options:
          temp_list.extend(_snake_case     )

          # checking breakpoints at which to pivot temporary sublist and add it into
          # keys_l
          if i in breakpoints or i == key_list_options[-1]:
             keys_l.extend(temp_list[::-1]     )
             temp_list.clear()

        # returning a shuffled keys_l to prevent brute force guessing of shift key
       return keys_l





    def 					__snake_case       (    self    :    Union[str, Any]     ):



       '''simple docstring'''







       snake_case   :							str						  =sum(self.__neg_pos([ord(_snake_case     ) for x in self.__passcode]     )     )
       return num if num > 0 else len(self.__passcode     )





    def 					__snake_case       (    self    :    Optional[int],    _snake_case    :    str     ):



       '''simple docstring'''







       snake_case   :							List[Any]						  =''''''

       # decoding shift like Caesar cipher algorithm implementing negative shift or
       # reverse shift or left shift
       for i in encoded_message:
          snake_case   :							Optional[int]						  =self.__key_list.index(_snake_case     )
          decoded_message += self.__key_list[
              (position - self.__shift_key) % -len(self.__key_list     )
          ]

       return decoded_message






    def 					__snake_case       (    self    :    Union[str, Any],    _snake_case    :    str     ):



       '''simple docstring'''







       snake_case   :							int						  =''''''

       # encoding shift like Caesar cipher algorithm implementing positive shift or
       # forward shift or right shift
       for i in plaintext:
          snake_case   :							int						  =self.__key_list.index(_snake_case     )
          encoded_message += self.__key_list[
              (position + self.__shift_key) % len(self.__key_list     )
          ]

       return encoded_message




def 		_a   (  lowerCamelCase_ = "Hello, this is a modified Caesar cipher"							):
   snake_case   :							List[Any]						  =ShuffledShiftCipher()
   return cipa.decrypt(cipa.encrypt(lowerCamelCase_							)							)


if __name__ == "__main__":
      import doctest

      doctest.testmod()





