


def   snake_case_    (			__lowercase      ,							__lowercase							):
   if not isinstance(__lowercase      ,							__lowercase							):
      raise TypeError('''plaintext must be a string'''							)
   if not isinstance(__lowercase      ,							__lowercase							):
      raise TypeError('''key must be a string'''							)

   if not plaintext:
      raise ValueError('''plaintext is empty'''							)
   if not key:
      raise ValueError('''key is empty'''							)

   key += plaintext
   UpperCAmelCase_				:   Optional[int]							= plaintext.lower()
   UpperCAmelCase_				:   int							= key.lower()
   UpperCAmelCase_				:   str							= 0
   UpperCAmelCase_				:   int							= 0
   UpperCAmelCase_				:   List[str]							= ''''''
   while plaintext_iterator < len(__lowercase							):
      if (
          ord(plaintext[plaintext_iterator]							) < 9_7
          or ord(plaintext[plaintext_iterator]							) > 1_2_2
      ):
         ciphertext += plaintext[plaintext_iterator]
         plaintext_iterator += 1
      elif ord(key[key_iterator]							) < 9_7 or ord(key[key_iterator]							) > 1_2_2:
         key_iterator += 1
      else:
         ciphertext += chr(
             (
                 (ord(plaintext[plaintext_iterator]							) - 9_7 + ord(key[key_iterator]							))
                 - 9_7
             )
             % 2_6
             + 9_7							)
         key_iterator += 1
         plaintext_iterator += 1
   return ciphertext
def   snake_case_    (			__lowercase      ,							__lowercase							):
   if not isinstance(__lowercase      ,							__lowercase							):
      raise TypeError('''ciphertext must be a string'''							)
   if not isinstance(__lowercase      ,							__lowercase							):
      raise TypeError('''key must be a string'''							)

   if not ciphertext:
      raise ValueError('''ciphertext is empty'''							)
   if not key:
      raise ValueError('''key is empty'''							)

   UpperCAmelCase_				:   str							= key.lower()
   UpperCAmelCase_				:   List[str]							= 0
   UpperCAmelCase_				:   str							= 0
   UpperCAmelCase_				:   Dict							= ''''''
   while ciphertext_iterator < len(__lowercase							):
      if (
          ord(ciphertext[ciphertext_iterator]							) < 9_7
          or ord(ciphertext[ciphertext_iterator]							) > 1_2_2
      ):
         plaintext += ciphertext[ciphertext_iterator]
      else:
         plaintext += chr(
             (ord(ciphertext[ciphertext_iterator]							) - ord(key[key_iterator]							)) % 2_6
             + 9_7							)
         key += chr(
             (ord(ciphertext[ciphertext_iterator]							) - ord(key[key_iterator]							)) % 2_6
             + 9_7							)
         key_iterator += 1
      ciphertext_iterator += 1
   return plaintext


if __name__ == "__main__":
       import doctest

       doctest.testmod()
       __UpperCamelCase					:	Tuple          =				int(input('Type 1 to encrypt or 2 to decrypt:'))
       if operation == 1:
              __UpperCamelCase					:	List[Any]          =				input('Typeplaintext to be encrypted:\n')
              __UpperCamelCase					:	List[Any]          =				input('Type the key:\n')
              print(encrypt(plaintext, key))
       elif operation == 2:
              __UpperCamelCase					:	List[Any]          =				input('Type the ciphertext to be decrypted:\n')
              __UpperCamelCase					:	Union[str, Any]          =				input('Type the key:\n')
              print(decrypt(ciphertext, key))
       decrypt('jsqqs avvwo', 'coffee')



import gc
import unittest

import numpy as np
import torch

from diffusers import RePaintPipeline, RePaintScheduler, UNetaDModel
from diffusers.utils.testing_utils import (
    enable_full_determinism,
    load_image,
    load_numpy,
    nightly,
    require_torch_gpu,
    skip_mps,
    torch_device,
)

from ..pipeline_params import IMAGE_INPAINTING_BATCH_PARAMS, IMAGE_INPAINTING_PARAMS
from ..test_pipelines_common import PipelineTesterMixin


enable_full_determinism()





class 			lowerCAmelCase__(     snake_case__     ,     unittest.TestCase    ):






    '''simple docstring'''





    A_	:  Tuple								=			RePaintPipeline
    A_	:  Tuple								=			IMAGE_INPAINTING_PARAMS - {'width', 'height', 'guidance_scale'}
    A_	:  str								=			PipelineTesterMixin.required_optional_params - {
        'latents',
        'num_images_per_prompt',
        'callback',
        'callback_steps',
    }
    A_	:  Optional[Any]								=			IMAGE_INPAINTING_BATCH_PARAMS
    A_	:  Union[str, Any]								=			False





    def        _lowerCamelCase			(						self					: Any						):





       '''simple docstring'''
       torch.manual_seed(0						)
       torch.manual_seed(0						)
       UpperCAmelCase_				:   int							= UNetaDModel(
           block_out_channels=(32, 64)							, layers_per_block=2							, sample_size=32							, in_channels=3							, out_channels=3							, down_block_types=('''DownBlock2D''', '''AttnDownBlock2D''')							, up_block_types=('''AttnUpBlock2D''', '''UpBlock2D''')							, )
       UpperCAmelCase_				:   str							= RePaintScheduler()
       UpperCAmelCase_				:   Optional[Any]							= {'''unet''': unet, '''scheduler''': scheduler}
       return components





    def        _lowerCamelCase			(						self					: List[str]							, __snake_case					: Optional[Any]							, __snake_case					: int=0						):





       '''simple docstring'''
       if str(__snake_case						).startswith('''mps'''						):
          UpperCAmelCase_				:   Optional[Any]							= torch.manual_seed(__snake_case						)
       else:
          UpperCAmelCase_				:   Optional[Any]							= torch.Generator(device=__snake_case						).manual_seed(__snake_case						)
       UpperCAmelCase_				:   Optional[Any]							= np.random.RandomState(__snake_case						).standard_normal((1, 3, 32, 32)						)
       UpperCAmelCase_				:   Optional[int]							= torch.from_numpy(__snake_case						).to(device=__snake_case							, dtype=torch.floataa						)
       UpperCAmelCase_				:   Any							= (image > 0).to(device=__snake_case							, dtype=torch.floataa						)
       UpperCAmelCase_				:   List[str]							= {
           '''image''': image,
           '''mask_image''': mask,
           '''generator''': generator,
           '''num_inference_steps''': 5,
           '''eta''': 0.0,
           '''jump_length''': 2,
           '''jump_n_sample''': 2,
           '''output_type''': '''numpy''',
       }
       return inputs





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





       '''simple docstring'''
       UpperCAmelCase_				:   str							= '''cpu'''  # ensure determinism for the device-dependent torch.Generator
       UpperCAmelCase_				:   Optional[int]							= self.get_dummy_components()
       UpperCAmelCase_				:   Dict							= RePaintPipeline(**__snake_case						)
       UpperCAmelCase_				:   int							= sd_pipe.to(__snake_case						)
       sd_pipe.set_progress_bar_config(disable=__snake_case						)

       UpperCAmelCase_				:   List[Any]							= self.get_dummy_inputs(__snake_case						)
       UpperCAmelCase_				:   Union[str, Any]							= sd_pipe(**__snake_case						).images
       UpperCAmelCase_				:   Optional[Any]							= image[0, -3:, -3:, -1]

       assert image.shape == (1, 32, 32, 3)
       UpperCAmelCase_				:   Tuple							= np.array([1.0_000, 0.5_426, 0.5_497, 0.2_200, 1.0_000, 1.0_000, 0.5_623, 1.0_000, 0.6_274]						)

       assert np.abs(image_slice.flatten() - expected_slice						).max() < 1E-3





    @skip_mps
    def        _lowerCamelCase			(						self					: Optional[int]						):





       '''simple docstring'''
       return super().test_save_load_local()





    @unittest.skip('''non-deterministic pipeline'''						)
    def        _lowerCamelCase			(						self					: Optional[Any]						):





       '''simple docstring'''
       return super().test_inference_batch_single_identical()





    @skip_mps
    def        _lowerCamelCase			(						self					: Dict						):





       '''simple docstring'''
       return super().test_dict_tuple_outputs_equivalent()





    @skip_mps
    def        _lowerCamelCase			(						self					: int						):





       '''simple docstring'''
       return super().test_save_load_optional_components()





    @skip_mps
    def        _lowerCamelCase			(						self					: Union[str, Any]						):





       '''simple docstring'''
       return super().test_attention_slicing_forward_pass()





@nightly
@require_torch_gpu
class 			lowerCAmelCase__(     unittest.TestCase    ):






    '''simple docstring'''





    def        _lowerCamelCase			(						self					: Tuple						):





       '''simple docstring'''
       super().tearDown()
       gc.collect()
       torch.cuda.empty_cache()





    def        _lowerCamelCase			(						self					: List[str]						):





       '''simple docstring'''
       UpperCAmelCase_				:   List[Any]							= load_image(
           '''https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/'''
           '''repaint/celeba_hq_256.png'''						)
       UpperCAmelCase_				:   int							= load_image(
           '''https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/repaint/mask_256.png'''						)
       UpperCAmelCase_				:   List[Any]							= load_numpy(
           '''https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/'''
           '''repaint/celeba_hq_256_result.npy'''						)

       UpperCAmelCase_				:   List[str]							= '''google/ddpm-ema-celebahq-256'''
       UpperCAmelCase_				:   Union[str, Any]							= UNetaDModel.from_pretrained(__snake_case						)
       UpperCAmelCase_				:   Dict							= RePaintScheduler.from_pretrained(__snake_case						)

       UpperCAmelCase_				:   Optional[int]							= RePaintPipeline(unet=__snake_case							, scheduler=__snake_case						).to(__snake_case						)
       repaint.set_progress_bar_config(disable=__snake_case						)
       repaint.enable_attention_slicing()

       UpperCAmelCase_				:   Optional[int]							= torch.manual_seed(0						)
       UpperCAmelCase_				:   List[str]							= repaint(
           __snake_case							, __snake_case							, num_inference_steps=250							, eta=0.0							, jump_length=10							, jump_n_sample=10							, generator=__snake_case							, output_type='''np'''							, )
       UpperCAmelCase_				:   Tuple							= output.images[0]

       assert image.shape == (256, 256, 3)
       assert np.abs(expected_image - image						).mean() < 1E-2