




import importlib
import sys
from argparse import REMAINDER, ArgumentParser
from pathlib import Path

import torch_xla.distributed.xla_multiprocessing as xmp



def   lowerCAmelCase						(						):




 """simple docstring"""







 UpperCAmelCase__								=  ArgumentParser(
     description=(
         "PyTorch TPU distributed training launch helper utility that will spawn up multiple distributed processes"
     )		)

 # Optional arguments for the launch helper
 parser.add_argument("--num_cores"  ,							type=_lowerCAmelCase  ,							default=1  ,							help="Number of TPU cores to use (1 or 8)."		)

 # positional
 parser.add_argument(
     "training_script"  ,							type=_lowerCAmelCase  ,							help=(
         "The full path to the single TPU training "
         "program/script to be launched in parallel, "
         "followed by all the arguments for the "
         "training script"
     )  ,							)

 # rest from the training program
 parser.add_argument("training_script_args"  ,							nargs=_lowerCAmelCase		)

 return parser.parse_args()



def   lowerCAmelCase						(						):




 """simple docstring"""







 UpperCAmelCase__								=  parse_args()

 # Import training_script as a module.
 UpperCAmelCase__								=  Path(args.training_script		)
 sys.path.append(str(script_fpath.parent.resolve()		)		)
 UpperCAmelCase__								=  script_fpath.stem
 UpperCAmelCase__								=  importlib.import_module(_lowerCAmelCase		)

 # Patch sys.argv
 UpperCAmelCase__								=  [args.training_script] + args.training_script_args + ["--tpu_num_cores", str(args.num_cores		)]

 xmp.spawn(mod._mp_fn  ,							args=()  ,							nprocs=args.num_cores		)


if __name__ == "__main__":
  main()











from __future__ import annotations

from string import ascii_letters



def   lowerCAmelCase						(						_lowerCAmelCase							:				str  ,							_lowerCAmelCase							:				int  ,							_lowerCAmelCase							:				str | None = None		):




 """simple docstring"""







 UpperCAmelCase__								=  alphabet or ascii_letters

 # The final result string
 UpperCAmelCase__								=  ""

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

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

 return result



def   lowerCAmelCase						(						_lowerCAmelCase							:				str  ,							_lowerCAmelCase							:				int  ,							_lowerCAmelCase							:				str | None = None		):




 """simple docstring"""







 key *= -1

 return encrypt(_lowerCAmelCase  ,							_lowerCAmelCase  ,							_lowerCAmelCase		)



def   lowerCAmelCase						(						_lowerCAmelCase							:				str  ,							_lowerCAmelCase							:				str | None = None		):




 """simple docstring"""







 UpperCAmelCase__								=  alphabet or ascii_letters

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

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

 return brute_force_data


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

    # get user input
    _lowerCAmelCase  :				List[Any]						=				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  :				Any						=				input("Please enter the string to be encrypted: ")
      _lowerCAmelCase  :				str						=				int(input("Please enter off-set: ").strip())

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

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

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

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





