





"""simple docstring"""




import random
import sys

from . import cryptomath_module as cryptomath

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





def        a_				(							_lowercase       ,						_lowercase       ,						_lowercase   ):
						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(_lowercase   ) - 1:
												sys.exit(
												    '''Key A must be greater than 0 and key B must '''
												    F"""be between 0 and {len(_lowercase   ) - 1}."""   )
						if cryptomath.gcd(_lowercase       ,						len(_lowercase   )   ) != 1:
												sys.exit(
												    F"""Key A {key_a} and the symbol set size {len(_lowercase   )} """
												    '''are not relatively prime. Choose a different key.'''   )





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





def        a_				(							_lowercase       ,						_lowercase   ):
						_UpperCamelCase   ,							_UpperCamelCase			:					Tuple     =    divmod(_lowercase       ,						len(_lowercase   )   )
						check_keys(_lowercase       ,						_lowercase       ,						'''decrypt'''   )
						_UpperCamelCase			:					List[Any]     =    ''''''
						_UpperCamelCase			:					Union[str, Any]     =    cryptomath.find_mod_inverse(_lowercase       ,						len(_lowercase   )   )
						for symbol in message:
												if symbol in SYMBOLS:
																		_UpperCamelCase			:					List[Any]     =    SYMBOLS.find(_lowercase   )
																		plain_text += SYMBOLS[
																		    (sym_index - key_b) * mod_inverse_of_key_a % len(_lowercase   )
																		]
												else:
																		plain_text += symbol
						return plain_text





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





def        a_				(							):
						_UpperCamelCase			:					Optional[Any]     =    input('''Enter message: '''   ).strip()
						_UpperCamelCase			:					Dict     =    int(input('''Enter key [2000 - 9000]: '''   ).strip()   )
						_UpperCamelCase			:					int     =    input('''Encrypt/Decrypt [E/D]: '''   ).strip().lower()

						if mode.startswith('''e'''   ):
												_UpperCamelCase			:					Any     =    '''encrypt'''
												_UpperCamelCase			:					Optional[Any]     =    encrypt_message(_lowercase       ,						_lowercase   )
						elif mode.startswith('''d'''   ):
												_UpperCamelCase			:					Optional[int]     =    '''decrypt'''
												_UpperCamelCase			:					Union[str, Any]     =    decrypt_message(_lowercase       ,						_lowercase   )
						print(F"""\n{mode.title()}ed text: \n{translated}"""   )


if __name__ == "__main__":
						import doctest

						doctest.testmod()
						# main()











"""simple docstring"""







import importlib.metadata
import subprocess
import sys





def 						lowercase__(A = False						)				->List[str]:




						"""simple docstring"""



						lowercase__				:      Any=       False
						if "IPython" in sys.modules:
												lowercase__				:      Tuple=       "google.colab" in str(sys.modules["IPython"].get_ipython()						)

						if in_colab:
												if upgrade:
																		lowercase__				:      Optional[int]=       ["pip", "install", "-U", "torch"]
																		subprocess.run(A					,		check=A						)
												# get the current version of torch
												lowercase__				:      Tuple=       importlib.metadata.version("torch"						)
												lowercase__				:      Dict=       torch_version[: torch_version.rindex("."						)]
												lowercase__				:      Dict=       f'''https://storage.googleapis.com/tpu-pytorch/wheels/colab/torch_xla-{torch_version_trunc}-cp37-cp37m-linux_x86_64.whl'''
												lowercase__				:      Union[str, Any]=       ["pip", "install", xla_wheel]
												subprocess.run(A					,		check=A						)
						else:
												raise RuntimeError("`install_xla` utility works only on google colab."						)






