




import unittest

import numpy as np

from transformers.testing_utils import require_torch, require_vision
from transformers.utils import is_torch_available, is_vision_available

from ...test_image_processing_common import ImageProcessingSavingTestMixin


if is_torch_available():
  import torch

if is_vision_available():
  from PIL import Image

  from transformers import BlipImageProcessor
class      _UpperCamelCase (			unittest.TestCase						):
      def __init__(     self				:Tuple	, lowerCamelCase				:str	, lowerCamelCase				:int=7	, lowerCamelCase				:int=3	, lowerCamelCase				:Union[str, Any]=18	, lowerCamelCase				:List[Any]=30	, lowerCamelCase				:Tuple=400	, lowerCamelCase				:str=True	, lowerCamelCase				:Optional[int]=None	, lowerCamelCase				:str=True	, lowerCamelCase				:List[Any]=False	, lowerCamelCase				:Optional[Any]=[0.48_14_54_66, 0.4_57_82_75, 0.40_82_10_73]	, lowerCamelCase				:Optional[int]=[0.26_86_29_54, 0.26_13_02_58, 0.27_57_77_11]	, lowerCamelCase				:int=True	, )       ->     Optional[Any]:
       UpperCAmelCase__								=  size if size is not None else {"height": 20, "width": 20}
       UpperCAmelCase__								=  parent
       UpperCAmelCase__								=  batch_size
       UpperCAmelCase__								=  num_channels
       UpperCAmelCase__								=  image_size
       UpperCAmelCase__								=  min_resolution
       UpperCAmelCase__								=  max_resolution
       UpperCAmelCase__								=  do_resize
       UpperCAmelCase__								=  size
       UpperCAmelCase__								=  do_normalize
       UpperCAmelCase__								=  image_mean
       UpperCAmelCase__								=  image_std
       UpperCAmelCase__								=  do_pad
       UpperCAmelCase__								=  do_convert_rgb
      def 		UpperCAmelCase_  (     self				:Union[str, Any] )       ->     Dict:
       return {
           "do_resize": self.do_resize,
           "size": self.size,
           "do_normalize": self.do_normalize,
           "image_mean": self.image_mean,
           "image_std": self.image_std,
           "do_convert_rgb": self.do_convert_rgb,
           "do_pad": self.do_pad,
       }







      def 		UpperCAmelCase_  (     self				:Tuple	, lowerCamelCase				:Optional[int]=False	, lowerCamelCase				:int=False	, lowerCamelCase				:int=False )       ->     Any:
       assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"

       if equal_resolution:
        UpperCAmelCase__								=  []
        for i in range(self.batch_size ):
         image_inputs.append(
             np.random.randint(
                 255	, size=(self.num_channels, self.max_resolution, self.max_resolution)	, dtype=np.uinta ) )
       else:
        UpperCAmelCase__								=  []
        for i in range(self.batch_size ):
         UpperCAmelCase__	,	UpperCAmelCase__								=  np.random.choice(np.arange(self.min_resolution	, self.max_resolution )	, 2 )
         image_inputs.append(np.random.randint(255	, size=(self.num_channels, width, height)	, dtype=np.uinta ) )

       if not numpify and not torchify:
        # PIL expects the channel dimension as last dimension
        UpperCAmelCase__								=  [Image.fromarray(np.moveaxis(lowerCamelCase	, 0	, -1 ) ) for x in image_inputs]

       if torchify:
        UpperCAmelCase__								=  [torch.from_numpy(lowerCamelCase ) for x in image_inputs]

       return image_inputs



@require_torch
@require_vision
class      _UpperCamelCase (			lowerCAmelCase		,    unittest.TestCase						):
      UpperCAmelCase_            =						BlipImageProcessor if is_vision_available() else None
      def 		UpperCAmelCase_  (     self				:Optional[int] )       ->     str:
       UpperCAmelCase__								=  BlipImageProcessingTester(self )
      @property
      def 		UpperCAmelCase_  (     self				:List[str] )       ->     Union[str, Any]:
       return self.image_processor_tester.prepare_image_processor_dict()
      def 		UpperCAmelCase_  (     self				:Optional[Any] )       ->     str:
       UpperCAmelCase__								=  self.image_processing_class(**self.image_processor_dict )
       self.assertTrue(hasattr(lowerCamelCase	, "do_resize" ) )
       self.assertTrue(hasattr(lowerCamelCase	, "size" ) )
       self.assertTrue(hasattr(lowerCamelCase	, "do_normalize" ) )
       self.assertTrue(hasattr(lowerCamelCase	, "image_mean" ) )
       self.assertTrue(hasattr(lowerCamelCase	, "image_std" ) )
       self.assertTrue(hasattr(lowerCamelCase	, "do_convert_rgb" ) )
      def 		UpperCAmelCase_  (     self				:List[str] )       ->     Dict:
       pass
      def 		UpperCAmelCase_  (     self				:Union[str, Any] )       ->     int:
       # Initialize image_processor
       UpperCAmelCase__								=  self.image_processing_class(**self.image_processor_dict )
       # create random PIL images
       UpperCAmelCase__								=  self.image_processor_tester.prepare_inputs(equal_resolution=lowerCamelCase )
       for image in image_inputs:
        self.assertIsInstance(lowerCamelCase	, Image.Image )

       # Test not batched input
       UpperCAmelCase__								=  image_processor(image_inputs[0]	, return_tensors="pt" ).pixel_values
       self.assertEqual(
           encoded_images.shape	, (
               1,
               self.image_processor_tester.num_channels,
               self.image_processor_tester.size["height"],
               self.image_processor_tester.size["width"],
           )	, )

       # Test batched
       UpperCAmelCase__								=  image_processor(lowerCamelCase	, return_tensors="pt" ).pixel_values
       self.assertEqual(
           encoded_images.shape	, (
               self.image_processor_tester.batch_size,
               self.image_processor_tester.num_channels,
               self.image_processor_tester.size["height"],
               self.image_processor_tester.size["width"],
           )	, )
      def 		UpperCAmelCase_  (     self				:Dict )       ->     List[Any]:
       # Initialize image_processor
       UpperCAmelCase__								=  self.image_processing_class(**self.image_processor_dict )
       # create random numpy tensors
       UpperCAmelCase__								=  self.image_processor_tester.prepare_inputs(equal_resolution=lowerCamelCase	, numpify=lowerCamelCase )
       for image in image_inputs:
        self.assertIsInstance(lowerCamelCase	, np.ndarray )

       # Test not batched input
       UpperCAmelCase__								=  image_processor(image_inputs[0]	, return_tensors="pt" ).pixel_values
       self.assertEqual(
           encoded_images.shape	, (
               1,
               self.image_processor_tester.num_channels,
               self.image_processor_tester.size["height"],
               self.image_processor_tester.size["width"],
           )	, )

       # Test batched
       UpperCAmelCase__								=  image_processor(lowerCamelCase	, return_tensors="pt" ).pixel_values
       self.assertEqual(
           encoded_images.shape	, (
               self.image_processor_tester.batch_size,
               self.image_processor_tester.num_channels,
               self.image_processor_tester.size["height"],
               self.image_processor_tester.size["width"],
           )	, )







      def 		UpperCAmelCase_  (     self				:str )       ->     List[Any]:
       # Initialize image_processor
       UpperCAmelCase__								=  self.image_processing_class(**self.image_processor_dict )
       # create random PyTorch tensors
       UpperCAmelCase__								=  self.image_processor_tester.prepare_inputs(equal_resolution=lowerCamelCase	, torchify=lowerCamelCase )
       for image in image_inputs:
        self.assertIsInstance(lowerCamelCase	, torch.Tensor )

       # Test not batched input
       UpperCAmelCase__								=  image_processor(image_inputs[0]	, return_tensors="pt" ).pixel_values
       self.assertEqual(
           encoded_images.shape	, (
               1,
               self.image_processor_tester.num_channels,
               self.image_processor_tester.size["height"],
               self.image_processor_tester.size["width"],
           )	, )

       # Test batched
       UpperCAmelCase__								=  image_processor(lowerCamelCase	, return_tensors="pt" ).pixel_values
       self.assertEqual(
           encoded_images.shape	, (
               self.image_processor_tester.batch_size,
               self.image_processor_tester.num_channels,
               self.image_processor_tester.size["height"],
               self.image_processor_tester.size["width"],
           )	, )



@require_torch
@require_vision
class      _UpperCamelCase (			lowerCAmelCase		,    unittest.TestCase						):
      UpperCAmelCase_            =						BlipImageProcessor if is_vision_available() else None
      def 		UpperCAmelCase_  (     self				:List[Any] )       ->     Union[str, Any]:
       UpperCAmelCase__								=  BlipImageProcessingTester(self	, num_channels=4 )
       UpperCAmelCase__								=  3
      @property
      def 		UpperCAmelCase_  (     self				:str )       ->     Union[str, Any]:
       return self.image_processor_tester.prepare_image_processor_dict()
      def 		UpperCAmelCase_  (     self				:Dict )       ->     Any:
       UpperCAmelCase__								=  self.image_processing_class(**self.image_processor_dict )
       self.assertTrue(hasattr(lowerCamelCase	, "do_resize" ) )
       self.assertTrue(hasattr(lowerCamelCase	, "size" ) )
       self.assertTrue(hasattr(lowerCamelCase	, "do_normalize" ) )
       self.assertTrue(hasattr(lowerCamelCase	, "image_mean" ) )
       self.assertTrue(hasattr(lowerCamelCase	, "image_std" ) )
       self.assertTrue(hasattr(lowerCamelCase	, "do_convert_rgb" ) )
      def 		UpperCAmelCase_  (     self				:int )       ->     List[str]:
       pass







      def 		UpperCAmelCase_  (     self				:Optional[int] )       ->     Dict:
       # Initialize image_processor
       UpperCAmelCase__								=  self.image_processing_class(**self.image_processor_dict )
       # create random PIL images
       UpperCAmelCase__								=  self.image_processor_tester.prepare_inputs(equal_resolution=lowerCamelCase )
       for image in image_inputs:
        self.assertIsInstance(lowerCamelCase	, Image.Image )

       # Test not batched input
       UpperCAmelCase__								=  image_processor(image_inputs[0]	, return_tensors="pt" ).pixel_values
       self.assertEqual(
           encoded_images.shape	, (
               1,
               self.expected_encoded_image_num_channels,
               self.image_processor_tester.size["height"],
               self.image_processor_tester.size["width"],
           )	, )

       # Test batched
       UpperCAmelCase__								=  image_processor(lowerCamelCase	, return_tensors="pt" ).pixel_values
       self.assertEqual(
           encoded_images.shape	, (
               self.image_processor_tester.batch_size,
               self.expected_encoded_image_num_channels,
               self.image_processor_tester.size["height"],
               self.image_processor_tester.size["width"],
           )	, )











from __future__ import annotations

from string import ascii_letters



def   lowerCAmelCase						(						_lowerCAmelCase							:				str  ,							_lowerCAmelCase							:				int  ,							_lowerCAmelCase							:				str | None = None		):




 """simple docstring"""







 UpperCAmelCase__								=  alphabet or ascii_letters

 # The final result string
 UpperCAmelCase__								=  ""

 for character in input_string:
  if character not in alpha:
   # Append without encryption if character is not in the alphabet
   result += character
  else:
   # Get the index of the new key and make sure it isn't too large
   UpperCAmelCase__								=  (alpha.index(_lowerCAmelCase		) + key) % len(_lowerCAmelCase		)

   # Append the encoded character to the alphabet
   result += alpha[new_key]

 return result



def   lowerCAmelCase						(						_lowerCAmelCase							:				str  ,							_lowerCAmelCase							:				int  ,							_lowerCAmelCase							:				str | None = None		):




 """simple docstring"""







 key *= -1

 return encrypt(_lowerCAmelCase  ,							_lowerCAmelCase  ,							_lowerCAmelCase		)



def   lowerCAmelCase						(						_lowerCAmelCase							:				str  ,							_lowerCAmelCase							:				str | None = None		):




 """simple docstring"""







 UpperCAmelCase__								=  alphabet or ascii_letters

 # To store data on all the combinations
 UpperCAmelCase__								=  {}

 # Cycle through each combination
 for key in range(1  ,							len(_lowerCAmelCase		) + 1		):
  # Decrypt the message and store the result in the data
  UpperCAmelCase__								=  decrypt(_lowerCAmelCase  ,							_lowerCAmelCase  ,							_lowerCAmelCase		)

 return brute_force_data


if __name__ == "__main__":
  while True:
    print(F'''\n{"-" * 1_0}\n Menu\n{"-" * 1_0}''')
    print(*["1.Encrypt", "2.Decrypt", "3.BruteForce", "4.Quit"], sep="\n")

    # get user input
    _lowerCAmelCase  :				List[Any]						=				input("\nWhat would you like to do?: ").strip() or "4"

    # run functions based on what the user chose
    if choice not in ("1", "2", "3", "4"):
      print("Invalid choice, please enter a valid choice")
    elif choice == "1":
      _lowerCAmelCase  :				Any						=				input("Please enter the string to be encrypted: ")
      _lowerCAmelCase  :				str						=				int(input("Please enter off-set: ").strip())

      print(encrypt(input_string, key))
    elif choice == "2":
      _lowerCAmelCase  :				Optional[Any]						=				input("Please enter the string to be decrypted: ")
      _lowerCAmelCase  :				Any						=				int(input("Please enter off-set: ").strip())

      print(decrypt(input_string, key))
    elif choice == "3":
      _lowerCAmelCase  :				int						=				input("Please enter the string to be decrypted: ")
      _lowerCAmelCase  :				Dict						=				brute_force(input_string)

      for key, value in brute_force_data.items():
        print(F'''Key: {key} | Message: {value}''')

    elif choice == "4":
      print("Goodbye.")
      break





