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    ,  _lowercase    )
        if pow(_lowercase    ,  2    ,  _lowercase    ) == 1:
            continue
        if pow(_lowercase    ,  _lowercase    ,  _lowercase    ) == 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(_lowercase    )  # select large prime number.
    __lowerCamelCase          =  primitive_root(_lowercase    )  # one primitive root on modulo p.
    __lowerCamelCase          =  random.randrange(3    ,  _lowercase    )  # private_key -> have to be greater than 2 for safety.
    __lowerCamelCase          =  cryptomath.find_mod_inverse(pow(_lowercase    ,  _lowercase    ,  _lowercase    )    ,  _lowercase    )

    __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          =  generate_key(_lowercase    )
    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_flax_available,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
)


__UpperCAmelCase												={
    "configuration_whisper": ["WHISPER_PRETRAINED_CONFIG_ARCHIVE_MAP", "WhisperConfig", "WhisperOnnxConfig"],
    "feature_extraction_whisper": ["WhisperFeatureExtractor"],
    "processing_whisper": ["WhisperProcessor"],
    "tokenization_whisper": ["WhisperTokenizer"],
}

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

try:
  if not is_torch_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  __UpperCAmelCase												=[
      "WHISPER_PRETRAINED_MODEL_ARCHIVE_LIST",
      "WhisperForConditionalGeneration",
      "WhisperModel",
      "WhisperPreTrainedModel",
      "WhisperForAudioClassification",
  ]

try:
  if not is_tf_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  __UpperCAmelCase												=[
      "TF_WHISPER_PRETRAINED_MODEL_ARCHIVE_LIST",
      "TFWhisperForConditionalGeneration",
      "TFWhisperModel",
      "TFWhisperPreTrainedModel",
  ]

try:
  if not is_flax_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  __UpperCAmelCase												=[
      "FlaxWhisperForConditionalGeneration",
      "FlaxWhisperModel",
      "FlaxWhisperPreTrainedModel",
      "FlaxWhisperForAudioClassification",
  ]


if TYPE_CHECKING:
  from .configuration_whisper import WHISPER_PRETRAINED_CONFIG_ARCHIVE_MAP, WhisperConfig, WhisperOnnxConfig
  from .feature_extraction_whisper import WhisperFeatureExtractor
  from .processing_whisper import WhisperProcessor
  from .tokenization_whisper import WhisperTokenizer

  try:
    if not is_tokenizers_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .tokenization_whisper_fast import WhisperTokenizerFast

  try:
    if not is_torch_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .modeling_whisper import (
        WHISPER_PRETRAINED_MODEL_ARCHIVE_LIST,
        WhisperForAudioClassification,
        WhisperForConditionalGeneration,
        WhisperModel,
        WhisperPreTrainedModel,
    )

  try:
    if not is_tf_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .modeling_tf_whisper import (
        TF_WHISPER_PRETRAINED_MODEL_ARCHIVE_LIST,
        TFWhisperForConditionalGeneration,
        TFWhisperModel,
        TFWhisperPreTrainedModel,
    )

  try:
    if not is_flax_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .modeling_flax_whisper import (
        FlaxWhisperForAudioClassification,
        FlaxWhisperForConditionalGeneration,
        FlaxWhisperModel,
        FlaxWhisperPreTrainedModel,
    )

else:
  import sys

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