






'''simple docstring'''



import os
import random
import sys

from . import cryptomath_module as cryptomath
from . import rabin_miller

SCREAMING_SNAKE_CASE						=	3


def 							lowercase_				(    __A :       int			)       ->      int:



 """simple docstring"""




 print('''Generating primitive root of p'''			)
 while True:
  lowercase					:   List[str]				  =random.randrange(3					,      __A			)
  if pow(__A					,      2					,      __A			) == 1:
   continue
  if pow(__A					,      __A					,      __A			) == 1:
   continue
  return g


def 							lowercase_				(    __A :       int			)       ->      tuple[tuple[int, int, int, int], tuple[int, int]]:



 """simple docstring"""




 print('''Generating prime p...'''			)
 lowercase					:   Any				  =rabin_miller.generate_large_prime(__A			)  # select large prime number.
 lowercase					:   List[str]				  =primitive_root(__A			)  # one primitive root on modulo p.
 lowercase					:   List[str]				  =random.randrange(3					,      __A			)  # private_key -> have to be greater than 2 for safety.
 lowercase					:   List[str]				  =cryptomath.find_mod_inverse(pow(__A					,      __A					,      __A			)					,      __A			)

 lowercase					:   Union[str, Any]				  =(key_size, e_a, e_a, p)
 lowercase					:   Optional[Any]				  =(key_size, d)

 return public_key, private_key


def 							lowercase_				(    __A :       str					,      __A :       int			)       ->      None:



 """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()

 lowercase					:   str				  =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 							lowercase_				(    )       ->      None:



 """simple docstring"""




 print('''Making key files...'''			)
 make_key_files('''elgamal'''					,      2_0_4_8			)
 print('''Key files generation successful'''			)


if __name__ == "__main__":
      main()











'''simple docstring'''



from typing import TYPE_CHECKING

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


SCREAMING_SNAKE_CASE						=	{
    'configuration_mega': ['MEGA_PRETRAINED_CONFIG_ARCHIVE_MAP', 'MegaConfig', 'MegaOnnxConfig'],
}

try:
      if not is_torch_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      SCREAMING_SNAKE_CASE						=	[
          'MEGA_PRETRAINED_MODEL_ARCHIVE_LIST',
          'MegaForCausalLM',
          'MegaForMaskedLM',
          'MegaForMultipleChoice',
          'MegaForQuestionAnswering',
          'MegaForSequenceClassification',
          'MegaForTokenClassification',
          'MegaModel',
          'MegaPreTrainedModel',
      ]

if TYPE_CHECKING:
      from .configuration_mega import MEGA_PRETRAINED_CONFIG_ARCHIVE_MAP, MegaConfig, MegaOnnxConfig

      try:
            if not is_torch_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .modeling_mega import (
                MEGA_PRETRAINED_MODEL_ARCHIVE_LIST,
                MegaForCausalLM,
                MegaForMaskedLM,
                MegaForMultipleChoice,
                MegaForQuestionAnswering,
                MegaForSequenceClassification,
                MegaForTokenClassification,
                MegaModel,
                MegaPreTrainedModel,
            )

else:
      import sys

      SCREAMING_SNAKE_CASE						=	_LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)



