


"""simple docstring"""







import random
import sys

from . import cryptomath_module as cryptomath

__a      			= (
    r" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`"
    r"abcdefghijklmnopqrstuvwxyz{|}~"
)






def        a__			(							_UpperCamelCase						,      _UpperCamelCase						,      _UpperCamelCase			):





						"""simple docstring"""

						if mode == "encrypt":
												if key_a == 1:
																		sys.exit(
																		    '''The affine cipher becomes weak when key '''
																		    '''A is set to 1. Choose different key'''			)
												if key_b == 0:
																		sys.exit(
																		    '''The affine cipher becomes weak when key '''
																		    '''B is set to 0. Choose different key'''			)
						if key_a < 0 or key_b < 0 or key_b > len(_UpperCamelCase			) - 1:
												sys.exit(
												    '''Key A must be greater than 0 and key B must '''
												    F"""be between 0 and {len(_UpperCamelCase			) - 1}."""			)
						if cryptomath.gcd(_UpperCamelCase						,      len(_UpperCamelCase			)			) != 1:
												sys.exit(
												    F"""Key A {key_a} and the symbol set size {len(_UpperCamelCase			)} """
												    '''are not relatively prime. Choose a different key.'''			)






def        a__			(							_UpperCamelCase						,      _UpperCamelCase			):





						"""simple docstring"""

						UpperCAmelCase__						,					UpperCAmelCase__												=     divmod(_UpperCamelCase						,      len(_UpperCamelCase			)			)
						check_keys(_UpperCamelCase						,      _UpperCamelCase						,      '''encrypt'''			)
						UpperCAmelCase__												=     ''''''
						for symbol in message:
												if symbol in SYMBOLS:
																		UpperCAmelCase__												=     SYMBOLS.find(_UpperCamelCase			)
																		cipher_text += SYMBOLS[(sym_index * key_a + key_b) % len(_UpperCamelCase			)]
												else:
																		cipher_text += symbol
						return cipher_text






def        a__			(							_UpperCamelCase						,      _UpperCamelCase			):





						"""simple docstring"""

						UpperCAmelCase__						,					UpperCAmelCase__												=     divmod(_UpperCamelCase						,      len(_UpperCamelCase			)			)
						check_keys(_UpperCamelCase						,      _UpperCamelCase						,      '''decrypt'''			)
						UpperCAmelCase__												=     ''''''
						UpperCAmelCase__												=     cryptomath.find_mod_inverse(_UpperCamelCase						,      len(_UpperCamelCase			)			)
						for symbol in message:
												if symbol in SYMBOLS:
																		UpperCAmelCase__												=     SYMBOLS.find(_UpperCamelCase			)
																		plain_text += SYMBOLS[
																		    (sym_index - key_b) * mod_inverse_of_key_a % len(_UpperCamelCase			)
																		]
												else:
																		plain_text += symbol
						return plain_text






def        a__			(							):





						"""simple docstring"""

						while True:
												UpperCAmelCase__												=     random.randint(2						,      len(_UpperCamelCase			)			)
												UpperCAmelCase__												=     random.randint(2						,      len(_UpperCamelCase			)			)
												if cryptomath.gcd(_UpperCamelCase						,      len(_UpperCamelCase			)			) == 1 and key_b % len(_UpperCamelCase			) != 0:
																		return key_b * len(_UpperCamelCase			) + key_b






def        a__			(							):





						"""simple docstring"""

						UpperCAmelCase__												=     input('''Enter message: '''			).strip()
						UpperCAmelCase__												=     int(input('''Enter key [2000 - 9000]: '''			).strip()			)
						UpperCAmelCase__												=     input('''Encrypt/Decrypt [E/D]: '''			).strip().lower()

						if mode.startswith('''e'''			):
												UpperCAmelCase__												=     '''encrypt'''
												UpperCAmelCase__												=     encrypt_message(_UpperCamelCase						,      _UpperCamelCase			)
						elif mode.startswith('''d'''			):
												UpperCAmelCase__												=     '''decrypt'''
												UpperCAmelCase__												=     decrypt_message(_UpperCamelCase						,      _UpperCamelCase			)
						print(F"""\n{mode.title()}ed text: \n{translated}"""			)


if __name__ == "__main__":
						import doctest

						doctest.testmod()
						# main()



"""simple docstring"""







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

import torch_xla.distributed.xla_multiprocessing as xmp






def        a__			(							):





						"""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=_UpperCamelCase						,      default=1						,      help='''Number of TPU cores to use (1 or 8).'''			)

						# positional
						parser.add_argument(
						    '''training_script'''						,      type=_UpperCamelCase						,      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=_UpperCamelCase			)

						return parser.parse_args()






def        a__			(							):





						"""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(_UpperCamelCase			)

						# 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()