


'''simple docstring'''


import random
import sys

from . import cryptomath_module as cryptomath

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







def     snake_case_     (						SCREAMING_SNAKE_CASE__							,   SCREAMING_SNAKE_CASE__							,   SCREAMING_SNAKE_CASE__  ):







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







def     snake_case_     (						SCREAMING_SNAKE_CASE__							,   SCREAMING_SNAKE_CASE__  ):







				"""simple docstring"""





				_SCREAMING_SNAKE_CASE				: Dict  	=   divmod(SCREAMING_SNAKE_CASE__							,   len(SCREAMING_SNAKE_CASE__  )  )
				check_keys(SCREAMING_SNAKE_CASE__							,   SCREAMING_SNAKE_CASE__							,   """encrypt"""  )
				_SCREAMING_SNAKE_CASE				: Dict  	=   """"""
				for symbol in message:
								if symbol in SYMBOLS:
												_SCREAMING_SNAKE_CASE				: Any  	=   SYMBOLS.find(SCREAMING_SNAKE_CASE__  )
												cipher_text += SYMBOLS[(sym_index * key_a + key_b) % len(SCREAMING_SNAKE_CASE__  )]
								else:
												cipher_text += symbol
				return cipher_text







def     snake_case_     (						SCREAMING_SNAKE_CASE__							,   SCREAMING_SNAKE_CASE__  ):







				"""simple docstring"""





				_SCREAMING_SNAKE_CASE				: Union[str, Any]  	=   divmod(SCREAMING_SNAKE_CASE__							,   len(SCREAMING_SNAKE_CASE__  )  )
				check_keys(SCREAMING_SNAKE_CASE__							,   SCREAMING_SNAKE_CASE__							,   """decrypt"""  )
				_SCREAMING_SNAKE_CASE				: Any  	=   """"""
				_SCREAMING_SNAKE_CASE				: Tuple  	=   cryptomath.find_mod_inverse(SCREAMING_SNAKE_CASE__							,   len(SCREAMING_SNAKE_CASE__  )  )
				for symbol in message:
								if symbol in SYMBOLS:
												_SCREAMING_SNAKE_CASE				: Optional[Any]  	=   SYMBOLS.find(SCREAMING_SNAKE_CASE__  )
												plain_text += SYMBOLS[
												    (sym_index - key_b) * mod_inverse_of_key_a % len(SCREAMING_SNAKE_CASE__  )
												]
								else:
												plain_text += symbol
				return plain_text







def     snake_case_     (						):







				"""simple docstring"""





				while True:
								_SCREAMING_SNAKE_CASE				: Optional[Any]  	=   random.randint(2							,   len(SCREAMING_SNAKE_CASE__  )  )
								_SCREAMING_SNAKE_CASE				: Any  	=   random.randint(2							,   len(SCREAMING_SNAKE_CASE__  )  )
								if cryptomath.gcd(SCREAMING_SNAKE_CASE__							,   len(SCREAMING_SNAKE_CASE__  )  ) == 1 and key_b % len(SCREAMING_SNAKE_CASE__  ) != 0:
												return key_b * len(SCREAMING_SNAKE_CASE__  ) + key_b







def     snake_case_     (						):







				"""simple docstring"""





				_SCREAMING_SNAKE_CASE				: Any  	=   input("""Enter message: """  ).strip()
				_SCREAMING_SNAKE_CASE				: Tuple  	=   int(input("""Enter key [2000 - 9000]: """  ).strip()  )
				_SCREAMING_SNAKE_CASE				: Dict  	=   input("""Encrypt/Decrypt [E/D]: """  ).strip().lower()

				if mode.startswith("""e"""  ):
								_SCREAMING_SNAKE_CASE				: Any  	=   """encrypt"""
								_SCREAMING_SNAKE_CASE				: Tuple  	=   encrypt_message(SCREAMING_SNAKE_CASE__							,   SCREAMING_SNAKE_CASE__  )
				elif mode.startswith("""d"""  ):
								_SCREAMING_SNAKE_CASE				: Optional[Any]  	=   """decrypt"""
								_SCREAMING_SNAKE_CASE				: List[Any]  	=   decrypt_message(SCREAMING_SNAKE_CASE__							,   SCREAMING_SNAKE_CASE__  )
				print(f"""\n{mode.title()}ed text: \n{translated}"""  )


if __name__ == "__main__":
						import doctest

						doctest.testmod()
						# main()








'''simple docstring'''


from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_flax_available,
    is_sentencepiece_available,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
)


UpperCAmelCase_	:     Union[str, Any]							     =	{'configuration_pegasus': ['PEGASUS_PRETRAINED_CONFIG_ARCHIVE_MAP', 'PegasusConfig']}

try:
				if not is_sentencepiece_available():
								raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
				pass
else:
				UpperCAmelCase_	:     Dict							     =	['PegasusTokenizer']

try:
				if not is_tokenizers_available():
								raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
				pass
else:
				UpperCAmelCase_	:     Optional[int]							     =	['PegasusTokenizerFast']

try:
				if not is_torch_available():
								raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
				pass
else:
				UpperCAmelCase_	:     Optional[int]							     =	[
				    'PEGASUS_PRETRAINED_MODEL_ARCHIVE_LIST',
				    'PegasusForCausalLM',
				    'PegasusForConditionalGeneration',
				    'PegasusModel',
				    'PegasusPreTrainedModel',
				]

try:
				if not is_tf_available():
								raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
				pass
else:
				UpperCAmelCase_	:     Optional[Any]							     =	[
				    'TFPegasusForConditionalGeneration',
				    'TFPegasusModel',
				    'TFPegasusPreTrainedModel',
				]

try:
				if not is_flax_available():
								raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
				pass
else:
				UpperCAmelCase_	:     Any							     =	[
				    'FlaxPegasusForConditionalGeneration',
				    'FlaxPegasusModel',
				    'FlaxPegasusPreTrainedModel',
				]


if TYPE_CHECKING:
				from .configuration_pegasus import PEGASUS_PRETRAINED_CONFIG_ARCHIVE_MAP, PegasusConfig

				try:
								if not is_sentencepiece_available():
												raise OptionalDependencyNotAvailable()
				except OptionalDependencyNotAvailable:
								pass
				else:
								from .tokenization_pegasus import PegasusTokenizer

				try:
								if not is_tokenizers_available():
												raise OptionalDependencyNotAvailable()
				except OptionalDependencyNotAvailable:
								pass
				else:
								from .tokenization_pegasus_fast import PegasusTokenizerFast

				try:
								if not is_torch_available():
												raise OptionalDependencyNotAvailable()
				except OptionalDependencyNotAvailable:
								pass
				else:
								from .modeling_pegasus import (
								    PEGASUS_PRETRAINED_MODEL_ARCHIVE_LIST,
								    PegasusForCausalLM,
								    PegasusForConditionalGeneration,
								    PegasusModel,
								    PegasusPreTrainedModel,
								)

				try:
								if not is_tf_available():
												raise OptionalDependencyNotAvailable()
				except OptionalDependencyNotAvailable:
								pass
				else:
								from .modeling_tf_pegasus import TFPegasusForConditionalGeneration, TFPegasusModel, TFPegasusPreTrainedModel

				try:
								if not is_flax_available():
												raise OptionalDependencyNotAvailable()
				except OptionalDependencyNotAvailable:
								pass
				else:
								from .modeling_flax_pegasus import (
								    FlaxPegasusForConditionalGeneration,
								    FlaxPegasusModel,
								    FlaxPegasusPreTrainedModel,
								)

else:
				import sys

				UpperCAmelCase_	:     List[str]							     =	_LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)




