



from __future__ import annotations

from string import ascii_letters


def 	_A	(   _UpperCamelCase      ,					_UpperCamelCase      ,					_UpperCamelCase = None			):
				_UpperCAmelCase						:  Optional[Any]     					=	alphabet or ascii_letters

				# The final result string
				_UpperCAmelCase						:  int     					=	''''''

				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						:  Tuple     					=	(alpha.index(a__			) + key) % len(a__			)

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

				return result


def 	_A	(   _UpperCamelCase      ,					_UpperCamelCase      ,					_UpperCamelCase = None			):
				key *= -1

				return encrypt(a__      ,					a__      ,					a__			)


def 	_A	(   _UpperCamelCase      ,					_UpperCamelCase = None			):
				_UpperCAmelCase						:  Any     					=	alphabet or ascii_letters

				# To store data on all the combinations
				_UpperCAmelCase						:  Tuple     					=	{}

				# Cycle through each combination
				for key in range(1      ,					len(a__			) + 1			):
								# Decrypt the message and store the result in the data
								_UpperCAmelCase						:  List[str]     					=	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
										UpperCAmelCase__			:   int      			=    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":
															UpperCAmelCase__			:   List[str]      			=    input('Please enter the string to be encrypted: ')
															UpperCAmelCase__			:   Optional[Any]      			=    int(input('Please enter off-set: ').strip())

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

															print(decrypt(input_string, key))
										elif choice == "3":
															UpperCAmelCase__			:   List[str]      			=    input('Please enter the string to be decrypted: ')
															UpperCAmelCase__			:   Union[str, Any]      			=    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'''







from typing import List, Optional, Tuple, Union

from . import logging
from .import_utils import is_torch_available, is_torch_version


if is_torch_available():
    import torch

lowerCAmelCase_      =   logging.get_logger(__name__)  # pylint: disable=invalid-name

try:
    from torch._dynamo import allow_in_graph as maybe_allow_in_graph
except (ImportError, ModuleNotFoundError):







    def   lowerCAmelCase(  cls    :  Dict      ):







           '''simple docstring'''






           return cls







def   lowerCAmelCase(  a__    :  Union[Tuple, List]      , a__    :  Optional[Union[List["torch.Generator"], "torch.Generator"]] = None      , a__    :  Optional["torch.device"] = None      , a__    :  Optional["torch.dtype"] = None      , a__    :  Optional["torch.layout"] = None      , ):







       '''simple docstring'''






       lowerCamelCase__				   =      device
       lowerCamelCase__				   =      shape[0]

       lowerCamelCase__				   =      layout or torch.strided
       lowerCamelCase__				   =      device or torch.device("cpu"      )

       if generator is not None:
              lowerCamelCase__				   =      generator.device.type if not isinstance(a__      , a__      ) else generator[0].device.type
              if gen_device_type != device.type and gen_device_type == "cpu":
                     lowerCamelCase__				   =      "cpu"
                     if device != "mps":
                            logger.info(
                                f"""The passed generator was created on 'cpu' even though a tensor on {device} was expected."""
                                f""" Tensors will be created on 'cpu' and then moved to {device}. Note that one can probably"""
                                f""" slighly speed up this function by passing a generator that was created on the {device} device."""      )
              elif gen_device_type != device.type and gen_device_type == "cuda":
                     raise ValueError(f"""Cannot generate a {device} tensor from a generator of type {gen_device_type}."""      )

       if isinstance(a__      , a__      ):
              lowerCamelCase__				   =      (1,) + shape[1:]
              lowerCamelCase__				   =      [
                  torch.randn(a__      , generator=generator[i]      , device=a__      , dtype=a__      , layout=a__      )
                  for i in range(a__      )
              ]
              lowerCamelCase__				   =      torch.cat(a__      , dim=0      ).to(a__      )
       else:
              lowerCamelCase__				   =      torch.randn(a__      , generator=a__      , device=a__      , dtype=a__      , layout=a__      ).to(a__      )

       return latents







def   lowerCAmelCase(  a__    :  Union[str, Any]      ):







       '''simple docstring'''






       if is_torch_version("<"      , "2.0.0"      ) or not hasattr(a__      , "_dynamo"      ):
              return False
       return isinstance(a__      , torch._dynamo.eval_frame.OptimizedModule      )

