


'''simple docstring'''






import os
import random
import sys

from . import cryptomath_module as cryptomath
from . import rabin_miller

__A :  List[Any]    							=				3







def     UpperCamelCase_      (   A__ :       int ):
		'''simple docstring'''





		print("""Generating primitive root of p""" )
		while True:
				lowerCAmelCase_      :				Tuple      =       random.randrange(3							,   A__ )
				if pow(A__							,   2							,   A__ ) == 1:
						continue
				if pow(A__							,   A__							,   A__ ) == 1:
						continue
				return g







def     UpperCamelCase_      (   A__ :       int ):
		'''simple docstring'''





		print("""Generating prime p...""" )
		lowerCAmelCase_      :				Union[str, Any]      =       rabin_miller.generate_large_prime(A__ )  # select large prime number.
		lowerCAmelCase_      :				Optional[int]      =       primitive_root(A__ )  # one primitive root on modulo p.
		lowerCAmelCase_      :				int      =       random.randrange(3							,   A__ )  # private_key -> have to be greater than 2 for safety.
		lowerCAmelCase_      :				Tuple      =       cryptomath.find_mod_inverse(pow(A__							,   A__							,   A__ )							,   A__ )

		lowerCAmelCase_      :				int      =       (key_size, e_a, e_a, p)
		lowerCAmelCase_      :				str      =       (key_size, d)

		return public_key, private_key







def     UpperCamelCase_      (   A__ :       str							,   A__ :       int ):
		'''simple docstring'''





		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_      :				Optional[Any]      =       generate_key(A__ )
		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     UpperCamelCase_      (   ):
		'''simple docstring'''





		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,
    is_vision_available,
)


__A :  List[str]    							=				{
    "configuration_owlvit": [
        "OWLVIT_PRETRAINED_CONFIG_ARCHIVE_MAP",
        "OwlViTConfig",
        "OwlViTOnnxConfig",
        "OwlViTTextConfig",
        "OwlViTVisionConfig",
    ],
    "processing_owlvit": ["OwlViTProcessor"],
}


try:
  if not is_vision_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  __A :  Optional[int]    							=				["OwlViTFeatureExtractor"]
  __A :  str    							=				["OwlViTImageProcessor"]

try:
  if not is_torch_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  __A :  Tuple    							=				[
      "OWLVIT_PRETRAINED_MODEL_ARCHIVE_LIST",
      "OwlViTModel",
      "OwlViTPreTrainedModel",
      "OwlViTTextModel",
      "OwlViTVisionModel",
      "OwlViTForObjectDetection",
  ]

if TYPE_CHECKING:
  from .configuration_owlvit import (
      OWLVIT_PRETRAINED_CONFIG_ARCHIVE_MAP,
      OwlViTConfig,
      OwlViTOnnxConfig,
      OwlViTTextConfig,
      OwlViTVisionConfig,
  )
  from .processing_owlvit import OwlViTProcessor

  try:
    if not is_vision_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .feature_extraction_owlvit import OwlViTFeatureExtractor
    from .image_processing_owlvit import OwlViTImageProcessor

  try:
    if not is_torch_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .modeling_owlvit import (
        OWLVIT_PRETRAINED_MODEL_ARCHIVE_LIST,
        OwlViTForObjectDetection,
        OwlViTModel,
        OwlViTPreTrainedModel,
        OwlViTTextModel,
        OwlViTVisionModel,
    )

else:
  import sys

  __A :  List[Any]    							=				_LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)



