


import unittest

import numpy as np
from datasets import load_dataset

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, prepare_image_inputs


if is_torch_available():
		import torch

if is_vision_available():
		from PIL import Image

		from transformers import SegformerImageProcessor





class    _a				(							unittest.TestCase):




	def __init__(   self		:						Tuple						,   _SCREAMING_SNAKE_CASE		:						Union[str, Any]						,   _SCREAMING_SNAKE_CASE		:						int=7						,   _SCREAMING_SNAKE_CASE		:						Optional[int]=3						,   _SCREAMING_SNAKE_CASE		:						Optional[int]=30						,   _SCREAMING_SNAKE_CASE		:						List[str]=400						,   _SCREAMING_SNAKE_CASE		:						List[str]=True						,   _SCREAMING_SNAKE_CASE		:						List[str]=None						,   _SCREAMING_SNAKE_CASE		:						str=True						,   _SCREAMING_SNAKE_CASE		:						Any=[0.5, 0.5, 0.5]						,   _SCREAMING_SNAKE_CASE		:						Optional[Any]=[0.5, 0.5, 0.5]						,   _SCREAMING_SNAKE_CASE		:						Dict=False						,   )->			Any:
			lowerCAmelCase__  :     List[Any]       	=   size if size is not None else {'''height''': 30, '''width''': 30}
			lowerCAmelCase__  :     str       	=   parent
			lowerCAmelCase__  :     Union[str, Any]       	=   batch_size
			lowerCAmelCase__  :     int       	=   num_channels
			lowerCAmelCase__  :     Optional[int]       	=   min_resolution
			lowerCAmelCase__  :     Optional[Any]       	=   max_resolution
			lowerCAmelCase__  :     Any       	=   do_resize
			lowerCAmelCase__  :     Dict       	=   size
			lowerCAmelCase__  :     Optional[int]       	=   do_normalize
			lowerCAmelCase__  :     str       	=   image_mean
			lowerCAmelCase__  :     Dict       	=   image_std
			lowerCAmelCase__  :     Any       	=   do_reduce_labels




	def 				UpperCAmelCase__(   self		:						Any						)->			Optional[int]:
			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_reduce_labels": self.do_reduce_labels,
			}






def 	lowerCamelCase_       (			):




		"""simple docstring"""






		lowerCAmelCase__  :     Union[str, Any]       	=   load_dataset('''hf-internal-testing/fixtures_ade20k'''      ,  split='''test'''			)

		lowerCAmelCase__  :     List[Any]       	=   Image.open(dataset[0]['''file''']			)
		lowerCAmelCase__  :     Tuple       	=   Image.open(dataset[1]['''file''']			)

		return image, map






def 	lowerCamelCase_       (			):




		"""simple docstring"""






		lowerCAmelCase__  :     Optional[int]       	=   load_dataset('''hf-internal-testing/fixtures_ade20k'''      ,  split='''test'''			)

		lowerCAmelCase__  :     List[str]       	=   Image.open(dataset[0]['''file''']			)
		lowerCAmelCase__  :     Any       	=   Image.open(dataset[1]['''file''']			)
		lowerCAmelCase__  :     List[Any]       	=   Image.open(dataset[2]['''file''']			)
		lowerCAmelCase__  :     List[str]       	=   Image.open(dataset[3]['''file''']			)

		return [imagea, imagea], [mapa, mapa]





@require_torch
@require_vision
class    _a				(							_lowercase	,		unittest.TestCase):
	_a    :    Any        =				SegformerImageProcessor if is_vision_available() else None




	def 				UpperCAmelCase__(   self		:						Tuple						)->			Dict:
			lowerCAmelCase__  :     Optional[int]       	=   SegformerImageProcessingTester(self						)




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




	def 				UpperCAmelCase__(   self		:						int						)->			List[str]:
			lowerCAmelCase__  :     Union[str, Any]       	=   self.image_processing_class(**self.image_processor_dict						)
			self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE						,   '''do_resize'''						)						)
			self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE						,   '''size'''						)						)
			self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE						,   '''do_normalize'''						)						)
			self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE						,   '''image_mean'''						)						)
			self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE						,   '''image_std'''						)						)
			self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE						,   '''do_reduce_labels'''						)						)




	def 				UpperCAmelCase__(   self		:						Tuple						)->			List[str]:
			lowerCAmelCase__  :     List[str]       	=   self.image_processing_class.from_dict(self.image_processor_dict						)
			self.assertEqual(image_processor.size						,   {'''height''': 30, '''width''': 30}						)
			self.assertEqual(image_processor.do_reduce_labels						,   _SCREAMING_SNAKE_CASE						)

			lowerCAmelCase__  :     Any       	=   self.image_processing_class.from_dict(self.image_processor_dict						,   size=42						,   reduce_labels=_SCREAMING_SNAKE_CASE						)
			self.assertEqual(image_processor.size						,   {'''height''': 42, '''width''': 42}						)
			self.assertEqual(image_processor.do_reduce_labels						,   _SCREAMING_SNAKE_CASE						)




	def 				UpperCAmelCase__(   self		:						List[Any]						)->			Optional[int]:
			pass




	def 				UpperCAmelCase__(   self		:						List[Any]						)->			Dict:
			# Initialize image_processing
			lowerCAmelCase__  :     Dict       	=   self.image_processing_class(**self.image_processor_dict						)
			# create random PIL images
			lowerCAmelCase__  :     Any       	=   prepare_image_inputs(self.image_processor_tester						,   equal_resolution=_SCREAMING_SNAKE_CASE						)
			for image in image_inputs:
					self.assertIsInstance(_SCREAMING_SNAKE_CASE						,   Image.Image						)

			# Test not batched input
			lowerCAmelCase__  :     List[str]       	=   image_processing(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
			lowerCAmelCase__  :     Union[str, Any]       	=   image_processing(_SCREAMING_SNAKE_CASE						,   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		:						Optional[int]						)->			str:
			# Initialize image_processing
			lowerCAmelCase__  :     List[str]       	=   self.image_processing_class(**self.image_processor_dict						)
			# create random numpy tensors
			lowerCAmelCase__  :     Tuple       	=   prepare_image_inputs(self.image_processor_tester						,   equal_resolution=_SCREAMING_SNAKE_CASE						,   numpify=_SCREAMING_SNAKE_CASE						)
			for image in image_inputs:
					self.assertIsInstance(_SCREAMING_SNAKE_CASE						,   np.ndarray						)

			# Test not batched input
			lowerCAmelCase__  :     str       	=   image_processing(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
			lowerCAmelCase__  :     int       	=   image_processing(_SCREAMING_SNAKE_CASE						,   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		:						int						)->			Tuple:
			# Initialize image_processing
			lowerCAmelCase__  :     Union[str, Any]       	=   self.image_processing_class(**self.image_processor_dict						)
			# create random PyTorch tensors
			lowerCAmelCase__  :     Union[str, Any]       	=   prepare_image_inputs(self.image_processor_tester						,   equal_resolution=_SCREAMING_SNAKE_CASE						,   torchify=_SCREAMING_SNAKE_CASE						)
			for image in image_inputs:
					self.assertIsInstance(_SCREAMING_SNAKE_CASE						,   torch.Tensor						)

			# Test not batched input
			lowerCAmelCase__  :     List[Any]       	=   image_processing(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
			lowerCAmelCase__  :     List[Any]       	=   image_processing(_SCREAMING_SNAKE_CASE						,   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		:						int						)->			List[str]:
			# Initialize image_processing
			lowerCAmelCase__  :     Union[str, Any]       	=   self.image_processing_class(**self.image_processor_dict						)
			# create random PyTorch tensors
			lowerCAmelCase__  :     List[Any]       	=   prepare_image_inputs(self.image_processor_tester						,   equal_resolution=_SCREAMING_SNAKE_CASE						,   torchify=_SCREAMING_SNAKE_CASE						)
			lowerCAmelCase__  :     Any       	=   []
			for image in image_inputs:
					self.assertIsInstance(_SCREAMING_SNAKE_CASE						,   torch.Tensor						)
					maps.append(torch.zeros(image.shape[-2:]						).long()						)

			# Test not batched input
			lowerCAmelCase__  :     List[str]       	=   image_processing(image_inputs[0]						,   maps[0]						,   return_tensors='''pt'''						)
			self.assertEqual(
			    encoding['''pixel_values'''].shape						,   (
			        1,
			        self.image_processor_tester.num_channels,
			        self.image_processor_tester.size['''height'''],
			        self.image_processor_tester.size['''width'''],
			    )						,   )
			self.assertEqual(
			    encoding['''labels'''].shape						,   (
			        1,
			        self.image_processor_tester.size['''height'''],
			        self.image_processor_tester.size['''width'''],
			    )						,   )
			self.assertEqual(encoding['''labels'''].dtype						,   torch.long						)
			self.assertTrue(encoding['''labels'''].min().item() >= 0						)
			self.assertTrue(encoding['''labels'''].max().item() <= 255						)

			# Test batched
			lowerCAmelCase__  :     Dict       	=   image_processing(_SCREAMING_SNAKE_CASE						,   _SCREAMING_SNAKE_CASE						,   return_tensors='''pt'''						)
			self.assertEqual(
			    encoding['''pixel_values'''].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'''],
			    )						,   )
			self.assertEqual(
			    encoding['''labels'''].shape						,   (
			        self.image_processor_tester.batch_size,
			        self.image_processor_tester.size['''height'''],
			        self.image_processor_tester.size['''width'''],
			    )						,   )
			self.assertEqual(encoding['''labels'''].dtype						,   torch.long						)
			self.assertTrue(encoding['''labels'''].min().item() >= 0						)
			self.assertTrue(encoding['''labels'''].max().item() <= 255						)

			# Test not batched input (PIL images)
			lowerCAmelCase__	,      lowerCAmelCase__  :     Optional[Any]       	=   prepare_semantic_single_inputs()

			lowerCAmelCase__  :     Any       	=   image_processing(_SCREAMING_SNAKE_CASE						,   _SCREAMING_SNAKE_CASE						,   return_tensors='''pt'''						)
			self.assertEqual(
			    encoding['''pixel_values'''].shape						,   (
			        1,
			        self.image_processor_tester.num_channels,
			        self.image_processor_tester.size['''height'''],
			        self.image_processor_tester.size['''width'''],
			    )						,   )
			self.assertEqual(
			    encoding['''labels'''].shape						,   (
			        1,
			        self.image_processor_tester.size['''height'''],
			        self.image_processor_tester.size['''width'''],
			    )						,   )
			self.assertEqual(encoding['''labels'''].dtype						,   torch.long						)
			self.assertTrue(encoding['''labels'''].min().item() >= 0						)
			self.assertTrue(encoding['''labels'''].max().item() <= 255						)

			# Test batched input (PIL images)
			lowerCAmelCase__	,      lowerCAmelCase__  :     Dict       	=   prepare_semantic_batch_inputs()

			lowerCAmelCase__  :     int       	=   image_processing(_SCREAMING_SNAKE_CASE						,   _SCREAMING_SNAKE_CASE						,   return_tensors='''pt'''						)
			self.assertEqual(
			    encoding['''pixel_values'''].shape						,   (
			        2,
			        self.image_processor_tester.num_channels,
			        self.image_processor_tester.size['''height'''],
			        self.image_processor_tester.size['''width'''],
			    )						,   )
			self.assertEqual(
			    encoding['''labels'''].shape						,   (
			        2,
			        self.image_processor_tester.size['''height'''],
			        self.image_processor_tester.size['''width'''],
			    )						,   )
			self.assertEqual(encoding['''labels'''].dtype						,   torch.long						)
			self.assertTrue(encoding['''labels'''].min().item() >= 0						)
			self.assertTrue(encoding['''labels'''].max().item() <= 255						)




	def 				UpperCAmelCase__(   self		:						Optional[Any]						)->			Dict:
			# Initialize image_processing
			lowerCAmelCase__  :     Tuple       	=   self.image_processing_class(**self.image_processor_dict						)

			# ADE20k has 150 classes, and the background is included, so labels should be between 0 and 150
			lowerCAmelCase__	,      lowerCAmelCase__  :     List[Any]       	=   prepare_semantic_single_inputs()
			lowerCAmelCase__  :     List[str]       	=   image_processing(_SCREAMING_SNAKE_CASE						,   _SCREAMING_SNAKE_CASE						,   return_tensors='''pt'''						)
			self.assertTrue(encoding['''labels'''].min().item() >= 0						)
			self.assertTrue(encoding['''labels'''].max().item() <= 150						)

			lowerCAmelCase__  :     List[Any]       	=   True
			lowerCAmelCase__  :     Union[str, Any]       	=   image_processing(_SCREAMING_SNAKE_CASE						,   _SCREAMING_SNAKE_CASE						,   return_tensors='''pt'''						)
			self.assertTrue(encoding['''labels'''].min().item() >= 0						)
			self.assertTrue(encoding['''labels'''].max().item() <= 255						)








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




