


"""simple docstring"""






import os
import random
import sys

from . import cryptomath_module as cryptomath
from . import rabin_miller

_lowerCamelCase     =  3


def __lowercase     (      lowerCamelCase_  :      int  ):
				print("Generating primitive root of p"  )
				while True:
								SCREAMING_SNAKE_CASE__     							=				random.randrange(3						,					lowerCamelCase_  )
								if pow(lowerCamelCase_						,					2						,					lowerCamelCase_  ) == 1:
												continue
								if pow(lowerCamelCase_						,					lowerCamelCase_						,					lowerCamelCase_  ) == 1:
												continue
								return g


def __lowercase     (      lowerCamelCase_  :      int  ):
				print("Generating prime p..."  )
				SCREAMING_SNAKE_CASE__     							=				rabin_miller.generate_large_prime(lowerCamelCase_  )  # select large prime number.
				SCREAMING_SNAKE_CASE__     							=				primitive_root(lowerCamelCase_  )  # one primitive root on modulo p.
				SCREAMING_SNAKE_CASE__     							=				random.randrange(3						,					lowerCamelCase_  )  # private_key -> have to be greater than 2 for safety.
				SCREAMING_SNAKE_CASE__     							=				cryptomath.find_mod_inverse(pow(lowerCamelCase_						,					lowerCamelCase_						,					lowerCamelCase_  )						,					lowerCamelCase_  )

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

				return public_key, private_key


def __lowercase     (      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()

				SCREAMING_SNAKE_CASE__							,      SCREAMING_SNAKE_CASE__     							=				generate_key(lowerCamelCase_  )
				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     (      ):
				print("Making key files..."  )
				make_key_files("elgamal"						,					2048  )
				print("Key files generation successful"  )


if __name__ == "__main__":
	main()




"""simple docstring"""






from typing import TYPE_CHECKING

# rely on isort to merge the imports
from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


_lowerCamelCase     =  {
    'configuration_autoformer': [
        'AUTOFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP',
        'AutoformerConfig',
    ],
}

try:
	if not is_torch_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	_lowerCamelCase     =  [
	    'AUTOFORMER_PRETRAINED_MODEL_ARCHIVE_LIST',
	    'AutoformerForPrediction',
	    'AutoformerModel',
	    'AutoformerPreTrainedModel',
	]


if TYPE_CHECKING:
	from .configuration_autoformer import (
	    AUTOFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP,
	    AutoformerConfig,
	)

	try:
		if not is_torch_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .modeling_autoformer import (
		    AUTOFORMER_PRETRAINED_MODEL_ARCHIVE_LIST,
		    AutoformerForPrediction,
		    AutoformerModel,
		    AutoformerPreTrainedModel,
		)

else:
	import sys

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