


"""simple docstring"""




import os
import random
import sys

from . import cryptomath_module as cryptomath
from . import rabin_miller

__UpperCamelCase						=      3


def     lowercase			(SCREAMING_SNAKE_CASE_		:				int  )   ->						int:
						print('Generating primitive root of p'  )
						while True:
												SCREAMING_SNAKE_CASE													=					random.randrange(3 ,			SCREAMING_SNAKE_CASE_  )
												if pow(SCREAMING_SNAKE_CASE_ ,			2 ,			SCREAMING_SNAKE_CASE_  ) == 1:
																		continue
												if pow(SCREAMING_SNAKE_CASE_ ,			SCREAMING_SNAKE_CASE_ ,			SCREAMING_SNAKE_CASE_  ) == 1:
																		continue
												return g


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

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

						return public_key, private_key


def     lowercase			(SCREAMING_SNAKE_CASE_		:				str ,			SCREAMING_SNAKE_CASE_		:				int  )   ->						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()

						SCREAMING_SNAKE_CASE							,				SCREAMING_SNAKE_CASE													=					generate_key(SCREAMING_SNAKE_CASE_  )
						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:
						print('Making key files...'  )
						make_key_files('elgamal' ,			20_48  )
						print('Key files generation successful'  )


if __name__ == "__main__":
	main()






"""simple docstring"""




# This is the module that test_patching.py uses to test patch_submodule()

import os  # noqa: this is just for tests
import os as renamed_os  # noqa: this is just for tests
from os import path  # noqa: this is just for tests
from os import path as renamed_path  # noqa: this is just for tests
from os.path import join  # noqa: this is just for tests
from os.path import join as renamed_join  # noqa: this is just for tests


__UpperCamelCase						=      open  # noqa: we just need to have a builtin inside this module to test it properly


