


"""simple docstring"""



from __future__ import annotations

from string import ascii_letters
def     UpperCAmelCase    (					_lowercase   :      str ,      _lowercase   :      int ,      _lowercase   :      str | None = None  )	->   str:


	"""simple docstring"""




	lowerCAmelCase_			       = alphabet or ascii_letters

	# The final result string
	lowerCAmelCase_			       = ''''''

	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_			       = (alpha.index(_lowercase  ) + key) % len(_lowercase  )

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

	return result
def     UpperCAmelCase    (					_lowercase   :      str ,      _lowercase   :      int ,      _lowercase   :      str | None = None  )	->   str:


	"""simple docstring"""




	key *= -1

	return encrypt(_lowercase ,      _lowercase ,      _lowercase  )
def     UpperCAmelCase    (					_lowercase   :      str ,      _lowercase   :      str | None = None  )	->   dict[int, str]:


	"""simple docstring"""




	lowerCAmelCase_			       = alphabet or ascii_letters

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

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

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

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

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

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

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



"""simple docstring"""



import torch

from diffusers import LMSDiscreteScheduler
from diffusers.utils import torch_device

from .test_schedulers import SchedulerCommonTest







class       __a	(   __snake_case       ):
				lowerCamelCase    :					Union[str, Any] 					=(LMSDiscreteScheduler,)
				lowerCamelCase    :					int 					=10







				def     lowerCamelCase_    (   self			,  **UpperCAmelCase      ):

					'''simple docstring'''






					lowerCAmelCase_			       = {
					    '''num_train_timesteps''': 1100,
					    '''beta_start''': 0.0_0_0_1,
					    '''beta_end''': 0.0_2,
					    '''beta_schedule''': '''linear''',
					}

					config.update(**UpperCAmelCase      )
					return config







				def     lowerCamelCase_    (   self      ):

					'''simple docstring'''






					for timesteps in [10, 50, 100, 1000]:
						self.check_over_configs(num_train_timesteps=UpperCAmelCase      )







				def     lowerCamelCase_    (   self      ):

					'''simple docstring'''






					for beta_start, beta_end in zip([0.0_0_0_0_1, 0.0_0_0_1, 0.0_0_1]			,  [0.0_0_0_2, 0.0_0_2, 0.0_2]      ):
						self.check_over_configs(beta_start=UpperCAmelCase			,  beta_end=UpperCAmelCase      )







				def     lowerCamelCase_    (   self      ):

					'''simple docstring'''






					for schedule in ["linear", "scaled_linear"]:
						self.check_over_configs(beta_schedule=UpperCAmelCase      )







				def     lowerCamelCase_    (   self      ):

					'''simple docstring'''






					for prediction_type in ["epsilon", "v_prediction"]:
						self.check_over_configs(prediction_type=UpperCAmelCase      )







				def     lowerCamelCase_    (   self      ):

					'''simple docstring'''






					for t in [0, 500, 800]:
						self.check_over_forward(time_step=UpperCAmelCase      )







				def     lowerCamelCase_    (   self      ):

					'''simple docstring'''






					lowerCAmelCase_			       = self.scheduler_classes[0]
					lowerCAmelCase_			       = self.get_scheduler_config()
					lowerCAmelCase_			       = scheduler_class(**UpperCAmelCase      )

					scheduler.set_timesteps(self.num_inference_steps      )

					lowerCAmelCase_			       = self.dummy_model()
					lowerCAmelCase_			       = self.dummy_sample_deter * scheduler.init_noise_sigma

					for i, t in enumerate(scheduler.timesteps      ):
						lowerCAmelCase_			       = scheduler.scale_model_input(UpperCAmelCase			,  UpperCAmelCase      )

						lowerCAmelCase_			       = model(UpperCAmelCase			,  UpperCAmelCase      )

						lowerCAmelCase_			       = scheduler.step(UpperCAmelCase			,  UpperCAmelCase			,  UpperCAmelCase      )
						lowerCAmelCase_			       = output.prev_sample

					lowerCAmelCase_			       = torch.sum(torch.abs(UpperCAmelCase      )      )
					lowerCAmelCase_			       = torch.mean(torch.abs(UpperCAmelCase      )      )

					assert abs(result_sum.item() - 1_0_0_6.3_8_8      ) < 1E-2
					assert abs(result_mean.item() - 1.3_1      ) < 1E-3







				def     lowerCamelCase_    (   self      ):

					'''simple docstring'''






					lowerCAmelCase_			       = self.scheduler_classes[0]
					lowerCAmelCase_			       = self.get_scheduler_config(prediction_type='''v_prediction'''      )
					lowerCAmelCase_			       = scheduler_class(**UpperCAmelCase      )

					scheduler.set_timesteps(self.num_inference_steps      )

					lowerCAmelCase_			       = self.dummy_model()
					lowerCAmelCase_			       = self.dummy_sample_deter * scheduler.init_noise_sigma

					for i, t in enumerate(scheduler.timesteps      ):
						lowerCAmelCase_			       = scheduler.scale_model_input(UpperCAmelCase			,  UpperCAmelCase      )

						lowerCAmelCase_			       = model(UpperCAmelCase			,  UpperCAmelCase      )

						lowerCAmelCase_			       = scheduler.step(UpperCAmelCase			,  UpperCAmelCase			,  UpperCAmelCase      )
						lowerCAmelCase_			       = output.prev_sample

					lowerCAmelCase_			       = torch.sum(torch.abs(UpperCAmelCase      )      )
					lowerCAmelCase_			       = torch.mean(torch.abs(UpperCAmelCase      )      )

					assert abs(result_sum.item() - 0.0_0_1_7      ) < 1E-2
					assert abs(result_mean.item() - 2.2_6_7_6E-0_6      ) < 1E-3







				def     lowerCamelCase_    (   self      ):

					'''simple docstring'''






					lowerCAmelCase_			       = self.scheduler_classes[0]
					lowerCAmelCase_			       = self.get_scheduler_config()
					lowerCAmelCase_			       = scheduler_class(**UpperCAmelCase      )

					scheduler.set_timesteps(self.num_inference_steps			,  device=UpperCAmelCase      )

					lowerCAmelCase_			       = self.dummy_model()
					lowerCAmelCase_			       = self.dummy_sample_deter * scheduler.init_noise_sigma.cpu()
					lowerCAmelCase_			       = sample.to(UpperCAmelCase      )

					for i, t in enumerate(scheduler.timesteps      ):
						lowerCAmelCase_			       = scheduler.scale_model_input(UpperCAmelCase			,  UpperCAmelCase      )

						lowerCAmelCase_			       = model(UpperCAmelCase			,  UpperCAmelCase      )

						lowerCAmelCase_			       = scheduler.step(UpperCAmelCase			,  UpperCAmelCase			,  UpperCAmelCase      )
						lowerCAmelCase_			       = output.prev_sample

					lowerCAmelCase_			       = torch.sum(torch.abs(UpperCAmelCase      )      )
					lowerCAmelCase_			       = torch.mean(torch.abs(UpperCAmelCase      )      )

					assert abs(result_sum.item() - 1_0_0_6.3_8_8      ) < 1E-2
					assert abs(result_mean.item() - 1.3_1      ) < 1E-3







				def     lowerCamelCase_    (   self      ):

					'''simple docstring'''






					lowerCAmelCase_			       = self.scheduler_classes[0]
					lowerCAmelCase_			       = self.get_scheduler_config()
					lowerCAmelCase_			       = scheduler_class(**UpperCAmelCase			,  use_karras_sigmas=UpperCAmelCase      )

					scheduler.set_timesteps(self.num_inference_steps			,  device=UpperCAmelCase      )

					lowerCAmelCase_			       = self.dummy_model()
					lowerCAmelCase_			       = self.dummy_sample_deter.to(UpperCAmelCase      ) * scheduler.init_noise_sigma
					lowerCAmelCase_			       = sample.to(UpperCAmelCase      )

					for t in scheduler.timesteps:
						lowerCAmelCase_			       = scheduler.scale_model_input(UpperCAmelCase			,  UpperCAmelCase      )

						lowerCAmelCase_			       = model(UpperCAmelCase			,  UpperCAmelCase      )

						lowerCAmelCase_			       = scheduler.step(UpperCAmelCase			,  UpperCAmelCase			,  UpperCAmelCase      )
						lowerCAmelCase_			       = output.prev_sample

					lowerCAmelCase_			       = torch.sum(torch.abs(UpperCAmelCase      )      )
					lowerCAmelCase_			       = torch.mean(torch.abs(UpperCAmelCase      )      )

					assert abs(result_sum.item() - 3_8_1_2.9_9_2_7      ) < 2E-2
					assert abs(result_mean.item() - 4.9_6_4_8      ) < 1E-3