


import inspect
import unittest

from transformers import ResNetConfig, is_flax_available
from transformers.testing_utils import require_flax, slow
from transformers.utils import cached_property, is_vision_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_flax_common import FlaxModelTesterMixin, floats_tensor


if is_flax_available():
		import jax
		import jax.numpy as jnp

		from transformers.models.resnet.modeling_flax_resnet import FlaxResNetForImageClassification, FlaxResNetModel

if is_vision_available():
		from PIL import Image

		from transformers import AutoImageProcessor





class    _a				(							unittest.TestCase):




	def __init__(   self		:						Optional[int]						,   _SCREAMING_SNAKE_CASE		:						Dict						,   _SCREAMING_SNAKE_CASE		:						Union[str, Any]=3						,   _SCREAMING_SNAKE_CASE		:						List[Any]=32						,   _SCREAMING_SNAKE_CASE		:						Union[str, Any]=3						,   _SCREAMING_SNAKE_CASE		:						Any=10						,   _SCREAMING_SNAKE_CASE		:						List[Any]=[10, 20, 30, 40]						,   _SCREAMING_SNAKE_CASE		:						str=[1, 1, 2, 1]						,   _SCREAMING_SNAKE_CASE		:						int=True						,   _SCREAMING_SNAKE_CASE		:						Tuple=True						,   _SCREAMING_SNAKE_CASE		:						Optional[int]="relu"						,   _SCREAMING_SNAKE_CASE		:						Dict=3						,   _SCREAMING_SNAKE_CASE		:						Tuple=None						,   )->			Tuple:
			lowerCAmelCase__  :     Dict       	=   parent
			lowerCAmelCase__  :     Optional[int]       	=   batch_size
			lowerCAmelCase__  :     Optional[int]       	=   image_size
			lowerCAmelCase__  :     str       	=   num_channels
			lowerCAmelCase__  :     Union[str, Any]       	=   embeddings_size
			lowerCAmelCase__  :     List[Any]       	=   hidden_sizes
			lowerCAmelCase__  :     Any       	=   depths
			lowerCAmelCase__  :     List[str]       	=   is_training
			lowerCAmelCase__  :     Union[str, Any]       	=   use_labels
			lowerCAmelCase__  :     Tuple       	=   hidden_act
			lowerCAmelCase__  :     List[Any]       	=   num_labels
			lowerCAmelCase__  :     List[Any]       	=   scope
			lowerCAmelCase__  :     Any       	=   len(_SCREAMING_SNAKE_CASE						)




	def 				UpperCAmelCase__(   self		:						Any						)->			int:
			lowerCAmelCase__  :     Union[str, Any]       	=   floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]						)

			lowerCAmelCase__  :     Union[str, Any]       	=   self.get_config()

			return config, pixel_values




	def 				UpperCAmelCase__(   self		:						Optional[Any]						)->			Tuple:
			return ResNetConfig(
			    num_channels=self.num_channels						,   embeddings_size=self.embeddings_size						,   hidden_sizes=self.hidden_sizes						,   depths=self.depths						,   hidden_act=self.hidden_act						,   num_labels=self.num_labels						,   image_size=self.image_size						,   )




	def 				UpperCAmelCase__(   self		:						List[Any]						,   _SCREAMING_SNAKE_CASE		:						Optional[Any]						,   _SCREAMING_SNAKE_CASE		:						str						)->			Dict:
			lowerCAmelCase__  :     int       	=   FlaxResNetModel(config=_SCREAMING_SNAKE_CASE						)
			lowerCAmelCase__  :     str       	=   model(_SCREAMING_SNAKE_CASE						)

			# Output shape (b, c, h, w)
			self.parent.assertEqual(
			    result.last_hidden_state.shape						,   (self.batch_size, self.hidden_sizes[-1], self.image_size // 32, self.image_size // 32)						,   )




	def 				UpperCAmelCase__(   self		:						List[str]						,   _SCREAMING_SNAKE_CASE		:						Any						,   _SCREAMING_SNAKE_CASE		:						List[Any]						)->			Union[str, Any]:
			lowerCAmelCase__  :     str       	=   self.num_labels
			lowerCAmelCase__  :     Optional[int]       	=   FlaxResNetForImageClassification(config=_SCREAMING_SNAKE_CASE						)
			lowerCAmelCase__  :     int       	=   model(_SCREAMING_SNAKE_CASE						)
			self.parent.assertEqual(result.logits.shape						,   (self.batch_size, self.num_labels)						)




	def 				UpperCAmelCase__(   self		:						Dict						)->			List[str]:
			lowerCAmelCase__  :     Any       	=   self.prepare_config_and_inputs()
			lowerCAmelCase__	,      lowerCAmelCase__  :     Optional[int]       	=   config_and_inputs
			lowerCAmelCase__  :     Union[str, Any]       	=   {'''pixel_values''': pixel_values}
			return config, inputs_dict





@require_flax
class    _a				(							_lowercase	,		unittest.TestCase):
	_a    :    Union[str, Any]        =				(FlaxResNetModel, FlaxResNetForImageClassification) if is_flax_available() else ()

	_a    :    int        =				False
	_a    :    Optional[int]        =				False
	_a    :    Tuple        =				False




	def 				UpperCAmelCase__(   self		:						List[str]						)->			None:
			lowerCAmelCase__  :     Optional[Any]       	=   FlaxResNetModelTester(self						)
			lowerCAmelCase__  :     Any       	=   ConfigTester(self						,   config_class=_SCREAMING_SNAKE_CASE						,   has_text_modality=_SCREAMING_SNAKE_CASE						)




	def 				UpperCAmelCase__(   self		:						Any						)->			List[str]:
			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 				UpperCAmelCase__(   self		:						int						)->			Union[str, Any]:
			return




	def 				UpperCAmelCase__(   self		:						str						)->			str:
			lowerCAmelCase__  :     Optional[int]       	=   self.model_tester.prepare_config_and_inputs()
			self.model_tester.create_and_check_model(*_SCREAMING_SNAKE_CASE						)




	def 				UpperCAmelCase__(   self		:						Optional[Any]						)->			List[Any]:
			lowerCAmelCase__  :     List[Any]       	=   self.model_tester.prepare_config_and_inputs()
			self.model_tester.create_and_check_for_image_classification(*_SCREAMING_SNAKE_CASE						)




	@unittest.skip(reason='''ResNet does not use inputs_embeds'''						)
	def 				UpperCAmelCase__(   self		:						str						)->			str:
			pass




	@unittest.skip(reason='''ResNet does not support input and output embeddings'''						)
	def 				UpperCAmelCase__(   self		:						Tuple						)->			Optional[int]:
			pass




	def 				UpperCAmelCase__(   self		:						Dict						)->			List[Any]:
			lowerCAmelCase__	,      lowerCAmelCase__  :     List[Any]       	=   self.model_tester.prepare_config_and_inputs_for_common()

			for model_class in self.all_model_classes:
					lowerCAmelCase__  :     List[str]       	=   model_class(_SCREAMING_SNAKE_CASE						)
					lowerCAmelCase__  :     Tuple       	=   inspect.signature(model.__call__						)
					# signature.parameters is an OrderedDict => so arg_names order is deterministic
					lowerCAmelCase__  :     Tuple       	=   [*signature.parameters.keys()]

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




	def 				UpperCAmelCase__(   self		:						Any						)->			Optional[int]:
			def check_hidden_states_output(_SCREAMING_SNAKE_CASE		:						List[str]						,   _SCREAMING_SNAKE_CASE		:						int						,   _SCREAMING_SNAKE_CASE		:						Optional[int]						):
					lowerCAmelCase__  :     str       	=   model_class(_SCREAMING_SNAKE_CASE						)

					lowerCAmelCase__  :     Union[str, Any]       	=   model(**self._prepare_for_class(_SCREAMING_SNAKE_CASE						,   _SCREAMING_SNAKE_CASE						)						)

					lowerCAmelCase__  :     Tuple       	=   outputs.encoder_hidden_states if config.is_encoder_decoder else outputs.hidden_states

					lowerCAmelCase__  :     List[Any]       	=   self.model_tester.num_stages
					self.assertEqual(len(_SCREAMING_SNAKE_CASE						)						,   expected_num_stages + 1						)




	@unittest.skip(reason='''ResNet does not use feedforward chunking'''						)
	def 				UpperCAmelCase__(   self		:						Union[str, Any]						)->			Any:
			pass




	def 				UpperCAmelCase__(   self		:						Optional[Any]						)->			Union[str, Any]:
			lowerCAmelCase__	,      lowerCAmelCase__  :     Optional[int]       	=   self.model_tester.prepare_config_and_inputs_for_common()

			for model_class in self.all_model_classes:
					with self.subTest(model_class.__name__						):
							lowerCAmelCase__  :     Dict       	=   self._prepare_for_class(_SCREAMING_SNAKE_CASE						,   _SCREAMING_SNAKE_CASE						)
							lowerCAmelCase__  :     Tuple       	=   model_class(_SCREAMING_SNAKE_CASE						)

							@jax.jit
							def model_jitted(_SCREAMING_SNAKE_CASE		:						Dict						,   **_SCREAMING_SNAKE_CASE		:						Union[str, Any]						):
									return model(pixel_values=_SCREAMING_SNAKE_CASE						,   **_SCREAMING_SNAKE_CASE						)

							with self.subTest('''JIT Enabled'''						):
									lowerCAmelCase__  :     Union[str, Any]       	=   model_jitted(**_SCREAMING_SNAKE_CASE						).to_tuple()

							with self.subTest('''JIT Disabled'''						):
									with jax.disable_jit():
											lowerCAmelCase__  :     Any       	=   model_jitted(**_SCREAMING_SNAKE_CASE						).to_tuple()

							self.assertEqual(len(_SCREAMING_SNAKE_CASE						)						,   len(_SCREAMING_SNAKE_CASE						)						)
							for jitted_output, output in zip(_SCREAMING_SNAKE_CASE						,   _SCREAMING_SNAKE_CASE						):
									self.assertEqual(jitted_output.shape						,   output.shape						)






def 	lowerCamelCase_       (			):




		"""simple docstring"""






		lowerCAmelCase__  :     Optional[int]       	=   Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''			)
		return image





@require_flax
class    _a				(							unittest.TestCase):




	@cached_property
	def 				UpperCAmelCase__(   self		:						Optional[int]						)->			Union[str, Any]:
			return AutoImageProcessor.from_pretrained('''microsoft/resnet-50'''						) if is_vision_available() else None




	@slow
	def 				UpperCAmelCase__(   self		:						List[Any]						)->			Dict:
			lowerCAmelCase__  :     Tuple       	=   FlaxResNetForImageClassification.from_pretrained('''microsoft/resnet-50'''						)

			lowerCAmelCase__  :     Optional[Any]       	=   self.default_image_processor
			lowerCAmelCase__  :     int       	=   prepare_img()
			lowerCAmelCase__  :     List[str]       	=   image_processor(images=_SCREAMING_SNAKE_CASE						,   return_tensors='''np'''						)

			lowerCAmelCase__  :     Any       	=   model(**_SCREAMING_SNAKE_CASE						)

			# verify the logits
			lowerCAmelCase__  :     int       	=   (1, 1000)
			self.assertEqual(outputs.logits.shape						,   _SCREAMING_SNAKE_CASE						)

			lowerCAmelCase__  :     str       	=   jnp.array([-11.1069, -9.7877, -8.3777]						)

			self.assertTrue(jnp.allclose(outputs.logits[0, :3]						,   _SCREAMING_SNAKE_CASE						,   atol=1E-4						)						)








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




