



'''simple docstring'''


import os
import random
import sys

from . import cryptomath_module as cryptomath
from . import rabin_miller

lowerCamelCase__    	=     3






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






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

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

		return public_key, private_key






def  __lowerCAmelCase (__lowerCAmelCase      , __lowerCAmelCase   ):
		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()

		_UpperCAmelCase		:       Dict								=      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 ():
		print("Making key files..."   )
		make_key_files("elgamal"      , 2_048   )
		print("Key files generation successful"   )


if __name__ == "__main__":
						main()







'''simple docstring'''


import os






def  __lowerCAmelCase ():
		_UpperCAmelCase		:       List[Any]								=      os.path.join(os.path.dirname(__lowerCAmelCase   )      , "num.txt"   )
		with open(__lowerCAmelCase   ) as file_hand:
				return str(sum(int(__lowerCAmelCase   ) for line in file_hand   )   )[:10]


if __name__ == "__main__":
						print(solution())



