



"""simple docstring"""

import os
import random
import sys

from . import cryptomath_module as cryptoMath  # noqa: N812
from . import rabin_miller as rabinMiller  # noqa: N812




def __lowercase    (							):
    print('''Making key files...'''					)
    make_key_files('''rsa'''	,    1_024					)
    print('''Key files generation successful.'''					)




def __lowercase    (							_a					):
    print('''Generating prime p...'''					)
    snake_case_				:  Union[str, Any]       =			rabinMiller.generate_large_prime(_a					)
    print('''Generating prime q...'''					)
    snake_case_				:  List[Any]       =			rabinMiller.generate_large_prime(_a					)
    snake_case_				:  str       =			p * q

    print('''Generating e that is relatively prime to (p - 1) * (q - 1)...'''					)
    while True:
        snake_case_				:  Any       =			random.randrange(2 ** (key_size - 1)	,    2 ** (key_size)					)
        if cryptoMath.gcd(_a	,    (p - 1) * (q - 1)					) == 1:
            break

    print('''Calculating d that is mod inverse of e...'''					)
    snake_case_				:  List[str]       =			cryptoMath.find_mod_inverse(_a	,    (p - 1) * (q - 1)					)

    snake_case_				:  List[Any]       =			(n, e)
    snake_case_				:  Tuple       =			(n, d)
    return (public_key, private_key)




def __lowercase    (							_a	,    _a					):
    if os.path.exists(f"{name}_pubkey.txt"					) or os.path.exists(f"{name}_privkey.txt"					):
        print('''\nWARNING:'''					)
        print(
            f"\"{name}_pubkey.txt\" or \"{name}_privkey.txt\" already exists. \n"
            '''Use a different name or delete these files and re-run this program.'''					)
        sys.exit()

    snake_case_,			snake_case_				:  str       =			generate_key(_a					)
    print(f"\nWriting public key to file {name}_pubkey.txt..."					)
    with open(f"{name}_pubkey.txt"	,    '''w'''					) as out_file:
        out_file.write(f"{key_size},{public_key[0]},{public_key[1]}"					)

    print(f"Writing private key to file {name}_privkey.txt..."					)
    with open(f"{name}_privkey.txt"	,    '''w'''					) as out_file:
        out_file.write(f"{key_size},{private_key[0]},{private_key[1]}"					)


if __name__ == "__main__":
     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,
)


lowercase__					:						List[Any]												=			{'''configuration_xglm''': ['''XGLM_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''XGLMConfig''']}

try:
     if not is_sentencepiece_available():
          raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
     pass
else:
     lowercase__					:						List[Any]												=			['''XGLMTokenizer''']

try:
     if not is_tokenizers_available():
          raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
     pass
else:
     lowercase__					:						List[str]												=			['''XGLMTokenizerFast''']

try:
     if not is_torch_available():
          raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
     pass
else:
     lowercase__					:						Tuple												=			[
         '''XGLM_PRETRAINED_MODEL_ARCHIVE_LIST''',
         '''XGLMForCausalLM''',
         '''XGLMModel''',
         '''XGLMPreTrainedModel''',
     ]


try:
     if not is_flax_available():
          raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
     pass
else:
     lowercase__					:						int												=			[
         '''FlaxXGLMForCausalLM''',
         '''FlaxXGLMModel''',
         '''FlaxXGLMPreTrainedModel''',
     ]


try:
     if not is_tf_available():
          raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
     pass
else:
     lowercase__					:						Tuple												=			[
         '''TF_XGLM_PRETRAINED_MODEL_ARCHIVE_LIST''',
         '''TFXGLMForCausalLM''',
         '''TFXGLMModel''',
         '''TFXGLMPreTrainedModel''',
     ]


if TYPE_CHECKING:
     from .configuration_xglm import XGLM_PRETRAINED_CONFIG_ARCHIVE_MAP, XGLMConfig

     try:
          if not is_sentencepiece_available():
               raise OptionalDependencyNotAvailable()
     except OptionalDependencyNotAvailable:
          pass
     else:
          from .tokenization_xglm import XGLMTokenizer

     try:
          if not is_tokenizers_available():
               raise OptionalDependencyNotAvailable()
     except OptionalDependencyNotAvailable:
          pass
     else:
          from .tokenization_xglm_fast import XGLMTokenizerFast

     try:
          if not is_torch_available():
               raise OptionalDependencyNotAvailable()
     except OptionalDependencyNotAvailable:
          pass
     else:
          from .modeling_xglm import XGLM_PRETRAINED_MODEL_ARCHIVE_LIST, XGLMForCausalLM, XGLMModel, XGLMPreTrainedModel

     try:
          if not is_flax_available():
               raise OptionalDependencyNotAvailable()
     except OptionalDependencyNotAvailable:
          pass
     else:
          from .modeling_flax_xglm import FlaxXGLMForCausalLM, FlaxXGLMModel, FlaxXGLMPreTrainedModel

     try:
          if not is_tf_available():
               raise OptionalDependencyNotAvailable()
     except OptionalDependencyNotAvailable:
          pass
     else:
          from .modeling_tf_xglm import (
              TF_XGLM_PRETRAINED_MODEL_ARCHIVE_LIST,
              TFXGLMForCausalLM,
              TFXGLMModel,
              TFXGLMPreTrainedModel,
          )


else:
     import sys

     lowercase__					:						List[Any]												=			_LazyModule(__name__, globals()['''__file__'''], _import_structure)





