


"""simple docstring"""






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 TvltImageProcessor
def    A_ ( _lowerCAmelCase  :       Tuple,  _lowerCAmelCase  :       Tuple=10,  _lowerCAmelCase  :       Optional[int]=10,  _lowerCAmelCase  :       str=False,  _lowerCAmelCase  :       Tuple=False							):






     """simple docstring"""

     _a     						=					[]
     for i in range(image_processor_tester.num_frames							):
          video.append(np.random.randint(2_55,  size=(image_processor_tester.num_channels, width, height),  dtype=np.uinta							)							)

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

     if torchify:
          _a     						=					[torch.from_numpy(_a							) for frame in video]

     return video
def    A_ ( _lowerCAmelCase  :       str,  _lowerCAmelCase  :       Optional[int]=False,  _lowerCAmelCase  :       List[str]=False,  _lowerCAmelCase  :       List[str]=False							):






     """simple docstring"""

     assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"

     _a     						=					[]
     for i in range(image_processor_tester.batch_size							):
          if equal_resolution:
               _a     						=					image_processor_tester.max_resolution
          else:
               _a     						=					np.random.choice(
                   np.arange(image_processor_tester.min_resolution,  image_processor_tester.max_resolution							),  2							)
               _a     						=					prepare_video(
                   image_processor_tester=_a,  width=_a,  height=_a,  numpify=_a,  torchify=_a,  )
          video_inputs.append(_a							)

     return video_inputs


class      __lowerCamelCase	(       unittest.TestCase					):

     '''simple docstring'''


     def __init__(   self     ,					__UpperCAmelCase     ,					__UpperCAmelCase=7     ,					__UpperCAmelCase=3     ,					__UpperCAmelCase=4     ,					__UpperCAmelCase=18     ,					__UpperCAmelCase=30     ,					__UpperCAmelCase=400     ,					__UpperCAmelCase=True     ,					__UpperCAmelCase=None     ,					__UpperCAmelCase=True     ,					__UpperCAmelCase=[0.5, 0.5, 0.5]     ,					__UpperCAmelCase=[0.5, 0.5, 0.5]     ,					__UpperCAmelCase=True     ,					__UpperCAmelCase=None     ,					)							->				List[str]:
          _a     						=					size if size is not None else {'''shortest_edge''': 18}
          _a     						=					crop_size if crop_size is not None else {'''height''': 18, '''width''': 18}

          _a     						=					parent
          _a     						=					batch_size
          _a     						=					num_channels
          _a     						=					num_frames
          _a     						=					image_size
          _a     						=					min_resolution
          _a     						=					max_resolution
          _a     						=					do_resize
          _a     						=					size
          _a     						=					do_normalize
          _a     						=					image_mean
          _a     						=					image_std
          _a     						=					do_center_crop
          _a     						=					crop_size





     def 				_UpperCAmelCase   (   self				)							->				str:
          return {
              "image_mean": self.image_mean,
              "image_std": self.image_std,
              "do_normalize": self.do_normalize,
              "do_resize": self.do_resize,
              "size": self.size,
              "do_center_crop": self.do_center_crop,
              "crop_size": self.crop_size,
          }







@require_torch
@require_vision
class      __lowerCamelCase	(       _lowercase	,       unittest.TestCase					):

     '''simple docstring'''
     A_							:						Any     =		TvltImageProcessor if is_vision_available() else None


     def 				_UpperCAmelCase   (   self				)							->				int:
          _a     						=					TvltImageProcessorTester(self				)


     @property
     def 				_UpperCAmelCase   (   self				)							->				Union[str, Any]:
          return self.image_processor_tester.prepare_image_processor_dict()


     def 				_UpperCAmelCase   (   self				)							->				Union[str, Any]:
          _a     						=					self.image_processing_class(**self.image_processor_dict				)
          self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE     ,					'''image_mean'''				)				)
          self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE     ,					'''image_std'''				)				)
          self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE     ,					'''do_normalize'''				)				)
          self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE     ,					'''do_resize'''				)				)
          self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE     ,					'''do_center_crop'''				)				)
          self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE     ,					'''size'''				)				)


     def 				_UpperCAmelCase   (   self				)							->				List[Any]:
          # Initialize image_processor
          _a     						=					self.image_processing_class(**self.image_processor_dict				)
          # create random PIL videos
          _a     						=					prepare_video_inputs(self.image_processor_tester     ,					equal_resolution=_SCREAMING_SNAKE_CASE				)
          for video in video_inputs:
               self.assertIsInstance(_SCREAMING_SNAKE_CASE     ,					_SCREAMING_SNAKE_CASE				)
               self.assertIsInstance(video[0]     ,					Image.Image				)

          # Test not batched input
          _a     						=					image_processor(video_inputs[0]     ,					return_tensors='''pt'''				).pixel_values
          self.assertEqual(
              encoded_videos.shape     ,					(
                  1,
                  self.image_processor_tester.num_frames,
                  self.image_processor_tester.num_channels,
                  self.image_processor_tester.crop_size['''height'''],
                  self.image_processor_tester.crop_size['''width'''],
              )     ,					)

          # Test batched
          _a     						=					image_processor(_SCREAMING_SNAKE_CASE     ,					return_tensors='''pt'''				).pixel_values
          self.assertEqual(
              encoded_videos.shape     ,					(
                  self.image_processor_tester.batch_size,
                  self.image_processor_tester.num_frames,
                  self.image_processor_tester.num_channels,
                  self.image_processor_tester.crop_size['''height'''],
                  self.image_processor_tester.crop_size['''width'''],
              )     ,					)


     def 				_UpperCAmelCase   (   self				)							->				Optional[int]:
          # Initialize image_processor
          _a     						=					self.image_processing_class(**self.image_processor_dict				)
          # create random numpy tensors
          _a     						=					prepare_video_inputs(self.image_processor_tester     ,					equal_resolution=_SCREAMING_SNAKE_CASE     ,					numpify=_SCREAMING_SNAKE_CASE				)
          for video in video_inputs:
               self.assertIsInstance(_SCREAMING_SNAKE_CASE     ,					_SCREAMING_SNAKE_CASE				)
               self.assertIsInstance(video[0]     ,					np.ndarray				)

          # Test not batched input
          _a     						=					image_processor(video_inputs[0]     ,					return_tensors='''pt'''				).pixel_values
          self.assertEqual(
              encoded_videos.shape     ,					(
                  1,
                  self.image_processor_tester.num_frames,
                  self.image_processor_tester.num_channels,
                  self.image_processor_tester.crop_size['''height'''],
                  self.image_processor_tester.crop_size['''width'''],
              )     ,					)

          # Test batched
          _a     						=					image_processor(_SCREAMING_SNAKE_CASE     ,					return_tensors='''pt'''				).pixel_values
          self.assertEqual(
              encoded_videos.shape     ,					(
                  self.image_processor_tester.batch_size,
                  self.image_processor_tester.num_frames,
                  self.image_processor_tester.num_channels,
                  self.image_processor_tester.crop_size['''height'''],
                  self.image_processor_tester.crop_size['''width'''],
              )     ,					)





     def 				_UpperCAmelCase   (   self				)							->				List[str]:
          # Initialize image_processor
          _a     						=					self.image_processing_class(**self.image_processor_dict				)
          # create random PyTorch tensors
          _a     						=					prepare_video_inputs(self.image_processor_tester     ,					equal_resolution=_SCREAMING_SNAKE_CASE     ,					torchify=_SCREAMING_SNAKE_CASE				)
          for video in video_inputs:
               self.assertIsInstance(_SCREAMING_SNAKE_CASE     ,					_SCREAMING_SNAKE_CASE				)
               self.assertIsInstance(video[0]     ,					torch.Tensor				)

          # Test not batched input
          _a     						=					image_processor(video_inputs[0]     ,					return_tensors='''pt'''				).pixel_values
          self.assertEqual(
              encoded_videos.shape     ,					(
                  1,
                  self.image_processor_tester.num_frames,
                  self.image_processor_tester.num_channels,
                  self.image_processor_tester.crop_size['''height'''],
                  self.image_processor_tester.crop_size['''width'''],
              )     ,					)

          # Test batched
          _a     						=					image_processor(_SCREAMING_SNAKE_CASE     ,					return_tensors='''pt'''				).pixel_values
          self.assertEqual(
              encoded_videos.shape     ,					(
                  self.image_processor_tester.batch_size,
                  self.image_processor_tester.num_frames,
                  self.image_processor_tester.num_channels,
                  self.image_processor_tester.crop_size['''height'''],
                  self.image_processor_tester.crop_size['''width'''],
              )     ,					)



from __future__ import annotations

from string import ascii_letters






def 	lowerCamelCase_       (			_a      ,  _a      ,  _a = None			):




		"""simple docstring"""






		lowerCAmelCase__  :     List[Any]       	=   alphabet or ascii_letters

		# The final result string
		lowerCAmelCase__  :     Optional[Any]       	=   ''''''

		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
						lowerCAmelCase__  :     int       	=   (alpha.index(_a			) + key) % len(_a			)

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

		return result






def 	lowerCamelCase_       (			_a      ,  _a      ,  _a = None			):




		"""simple docstring"""






		key *= -1

		return encrypt(_a      ,  _a      ,  _a			)






def 	lowerCamelCase_       (			_a      ,  _a = None			):




		"""simple docstring"""






		lowerCAmelCase__  :     Optional[Any]       	=   alphabet or ascii_letters

		# To store data on all the combinations
		lowerCAmelCase__  :     Optional[int]       	=   {}

		# Cycle through each combination
		for key in range(1      ,  len(_a			) + 1			):
				# Decrypt the message and store the result in the data
				lowerCAmelCase__  :     Optional[int]       	=   decrypt(_a      ,  _a      ,  _a			)

		return brute_force_data


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

				# get user input
				lowerCamelCase		=						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		=						input('''Please enter the string to be encrypted: ''')
						lowerCamelCase		=						int(input('''Please enter off-set: ''').strip())

						print(encrypt(input_string, key))
				elif choice == "2":
						lowerCamelCase		=						input('''Please enter the string to be decrypted: ''')
						lowerCamelCase		=						int(input('''Please enter off-set: ''').strip())

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

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

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




