





'''simple docstring'''

from typing import TYPE_CHECKING

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


__lowerCAmelCase							:     int		     ={
    "configuration_convbert": ["CONVBERT_PRETRAINED_CONFIG_ARCHIVE_MAP", "ConvBertConfig", "ConvBertOnnxConfig"],
    "tokenization_convbert": ["ConvBertTokenizer"],
}

try:
  if not is_tokenizers_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  __lowerCAmelCase							:     List[Any]		     =["ConvBertTokenizerFast"]

try:
  if not is_torch_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  __lowerCAmelCase							:     int		     =[
      "CONVBERT_PRETRAINED_MODEL_ARCHIVE_LIST",
      "ConvBertForMaskedLM",
      "ConvBertForMultipleChoice",
      "ConvBertForQuestionAnswering",
      "ConvBertForSequenceClassification",
      "ConvBertForTokenClassification",
      "ConvBertLayer",
      "ConvBertModel",
      "ConvBertPreTrainedModel",
      "load_tf_weights_in_convbert",
  ]


try:
  if not is_tf_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  __lowerCAmelCase							:     str		     =[
      "TF_CONVBERT_PRETRAINED_MODEL_ARCHIVE_LIST",
      "TFConvBertForMaskedLM",
      "TFConvBertForMultipleChoice",
      "TFConvBertForQuestionAnswering",
      "TFConvBertForSequenceClassification",
      "TFConvBertForTokenClassification",
      "TFConvBertLayer",
      "TFConvBertModel",
      "TFConvBertPreTrainedModel",
  ]


if TYPE_CHECKING:
  from .configuration_convbert import CONVBERT_PRETRAINED_CONFIG_ARCHIVE_MAP, ConvBertConfig, ConvBertOnnxConfig
  from .tokenization_convbert import ConvBertTokenizer

  try:
    if not is_tokenizers_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .tokenization_convbert_fast import ConvBertTokenizerFast

  try:
    if not is_torch_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .modeling_convbert import (
        CONVBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
        ConvBertForMaskedLM,
        ConvBertForMultipleChoice,
        ConvBertForQuestionAnswering,
        ConvBertForSequenceClassification,
        ConvBertForTokenClassification,
        ConvBertLayer,
        ConvBertModel,
        ConvBertPreTrainedModel,
        load_tf_weights_in_convbert,
    )

  try:
    if not is_tf_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .modeling_tf_convbert import (
        TF_CONVBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
        TFConvBertForMaskedLM,
        TFConvBertForMultipleChoice,
        TFConvBertForQuestionAnswering,
        TFConvBertForSequenceClassification,
        TFConvBertForTokenClassification,
        TFConvBertLayer,
        TFConvBertModel,
        TFConvBertPreTrainedModel,
    )


else:
  import sys

  __lowerCAmelCase							:     str		     =_LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)










'''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 						UpperCamelCase    (							):
    print("Making key files..."	)
    make_key_files("rsa"						,	10_24	)
    print("Key files generation successful."	)





def 						UpperCamelCase    (							_lowerCamelCase : int	):
    print("Generating prime p..."	)
    A__    =      rabinMiller.generate_large_prime(_lowerCamelCase	)
    print("Generating prime q..."	)
    A__    =      rabinMiller.generate_large_prime(_lowerCamelCase	)
    A__    =      p * q

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

    print("Calculating d that is mod inverse of e..."	)
    A__    =      cryptoMath.find_mod_inverse(_lowerCamelCase						,	(p - 1) * (q - 1)	)

    A__    =      (n, e)
    A__    =      (n, d)
    return (public_key, private_key)





def 						UpperCamelCase    (							_lowerCamelCase : str						,	_lowerCamelCase : int	):
    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()

    A__,     A__    =      generate_key(_lowerCamelCase	)
    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()



