'''simple docstring'''




import os
import random
import sys

from . import cryptomath_module as cryptomath
from . import rabin_miller

__UpperCAmelCase					=3






def __lowerCAmelCase					(				UpperCamelCase__							)      ->       int:
    print('''Generating primitive root of p'''							)
    while True:
        __lowerCamelCase            =    random.randrange(3							,    UpperCamelCase__							)
        if pow(UpperCamelCase__							,    2							,    UpperCamelCase__							) == 1:
            continue
        if pow(UpperCamelCase__							,    UpperCamelCase__							,    UpperCamelCase__							) == 1:
            continue
        return g






def __lowerCAmelCase					(				UpperCamelCase__							)      ->       tuple[tuple[int, int, int, int], tuple[int, int]]:
    print('''Generating prime p...'''							)
    __lowerCamelCase            =    rabin_miller.generate_large_prime(UpperCamelCase__							)  # select large prime number.
    __lowerCamelCase            =    primitive_root(UpperCamelCase__							)  # one primitive root on modulo p.
    __lowerCamelCase            =    random.randrange(3							,    UpperCamelCase__							)  # private_key -> have to be greater than 2 for safety.
    __lowerCamelCase            =    cryptomath.find_mod_inverse(pow(UpperCamelCase__							,    UpperCamelCase__							,    UpperCamelCase__							)							,    UpperCamelCase__							)

    __lowerCamelCase            =    (key_size, e_a, e_a, p)
    __lowerCamelCase            =    (key_size, d)

    return public_key, private_key






def __lowerCAmelCase					(				UpperCamelCase__							,    UpperCamelCase__							)      ->       None:
    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()

    __lowerCamelCase      ,    __lowerCamelCase            =    generate_key(UpperCamelCase__							)
    print(f"""\nWriting public key to file {name}_pubkey.txt..."""							)
    with open(f"""{name}_pubkey.txt"""							,    '''w'''							) as fo:
        fo.write(f"""{public_key[0]},{public_key[1]},{public_key[2]},{public_key[3]}"""							)

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






def __lowerCAmelCase					(				)      ->       None:
    print('''Making key files...'''							)
    make_key_files('''elgamal'''							,    20_48							)
    print('''Key files generation successful'''							)


if __name__ == "__main__":
  main()

'''simple docstring'''




from typing import TYPE_CHECKING

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


__UpperCAmelCase					={
    "configuration_mobilebert": [
        "MOBILEBERT_PRETRAINED_CONFIG_ARCHIVE_MAP",
        "MobileBertConfig",
        "MobileBertOnnxConfig",
    ],
    "tokenization_mobilebert": ["MobileBertTokenizer"],
}

try:
  if not is_tokenizers_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  __UpperCAmelCase					=["MobileBertTokenizerFast"]

try:
  if not is_torch_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  __UpperCAmelCase					=[
      "MOBILEBERT_PRETRAINED_MODEL_ARCHIVE_LIST",
      "MobileBertForMaskedLM",
      "MobileBertForMultipleChoice",
      "MobileBertForNextSentencePrediction",
      "MobileBertForPreTraining",
      "MobileBertForQuestionAnswering",
      "MobileBertForSequenceClassification",
      "MobileBertForTokenClassification",
      "MobileBertLayer",
      "MobileBertModel",
      "MobileBertPreTrainedModel",
      "load_tf_weights_in_mobilebert",
  ]

try:
  if not is_tf_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  __UpperCAmelCase					=[
      "TF_MOBILEBERT_PRETRAINED_MODEL_ARCHIVE_LIST",
      "TFMobileBertForMaskedLM",
      "TFMobileBertForMultipleChoice",
      "TFMobileBertForNextSentencePrediction",
      "TFMobileBertForPreTraining",
      "TFMobileBertForQuestionAnswering",
      "TFMobileBertForSequenceClassification",
      "TFMobileBertForTokenClassification",
      "TFMobileBertMainLayer",
      "TFMobileBertModel",
      "TFMobileBertPreTrainedModel",
  ]


if TYPE_CHECKING:
  from .configuration_mobilebert import (
      MOBILEBERT_PRETRAINED_CONFIG_ARCHIVE_MAP,
      MobileBertConfig,
      MobileBertOnnxConfig,
  )
  from .tokenization_mobilebert import MobileBertTokenizer

  try:
    if not is_tokenizers_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .tokenization_mobilebert_fast import MobileBertTokenizerFast

  try:
    if not is_torch_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .modeling_mobilebert import (
        MOBILEBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
        MobileBertForMaskedLM,
        MobileBertForMultipleChoice,
        MobileBertForNextSentencePrediction,
        MobileBertForPreTraining,
        MobileBertForQuestionAnswering,
        MobileBertForSequenceClassification,
        MobileBertForTokenClassification,
        MobileBertLayer,
        MobileBertModel,
        MobileBertPreTrainedModel,
        load_tf_weights_in_mobilebert,
    )

  try:
    if not is_tf_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .modeling_tf_mobilebert import (
        TF_MOBILEBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
        TFMobileBertForMaskedLM,
        TFMobileBertForMultipleChoice,
        TFMobileBertForNextSentencePrediction,
        TFMobileBertForPreTraining,
        TFMobileBertForQuestionAnswering,
        TFMobileBertForSequenceClassification,
        TFMobileBertForTokenClassification,
        TFMobileBertMainLayer,
        TFMobileBertModel,
        TFMobileBertPreTrainedModel,
    )

else:
  import sys

  __UpperCAmelCase					=_LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)
