




import os
import random
import sys

from . import cryptomath_module as cryptoMath  # noqa: N812
from . import rabin_miller as rabinMiller  # noqa: N812


def 		lowerCamelCase__       (						):







	'''simple docstring'''





	print("Making key files..."				)
	make_key_files("rsa"	,      1024				)
	print("Key files generation successful."				)


def 		lowerCamelCase__       (						_A				):







	'''simple docstring'''





	print("Generating prime p..."				)
	snake_case_						       =	rabinMiller.generate_large_prime(_A				)
	print("Generating prime q..."				)
	snake_case_						       =	rabinMiller.generate_large_prime(_A				)
	snake_case_						       =	p * q

	print("Generating e that is relatively prime to (p - 1) * (q - 1)..."				)
	while True:
		snake_case_						       =	random.randrange(2 ** (key_size - 1)	,      2 ** (key_size)				)
		if cryptoMath.gcd(_A	,      (p - 1) * (q - 1)				) == 1:
			break

	print("Calculating d that is mod inverse of e..."				)
	snake_case_						       =	cryptoMath.find_mod_inverse(_A	,      (p - 1) * (q - 1)				)

	snake_case_						       =	(n, e)
	snake_case_						       =	(n, d)
	return (public_key, private_key)


def 		lowerCamelCase__       (						_A	,      _A				):







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

	snake_case_       , snake_case_						       =	generate_key(_A				)
	print(f"\nWriting public key to file {name}_pubkey.txt..."				)
	with open(f"{name}_pubkey.txt"	,      "w"				) as out_file:
		out_file.write(f"{key_size},{public_key[0]},{public_key[1]}"				)

	print(f"Writing private key to file {name}_privkey.txt..."				)
	with open(f"{name}_privkey.txt"	,      "w"				) as out_file:
		out_file.write(f"{key_size},{private_key[0]},{private_key[1]}"				)


if __name__ == "__main__":
		main()






def 		lowerCamelCase__       (						):







	'''simple docstring'''





	for n in range(1	,      1000000				):
		yield n * (n + 1) // 2


def 		lowerCamelCase__       (						_A				):







	'''simple docstring'''





	snake_case_						       =	1
	snake_case_						       =	2
	while i * i <= n:
		snake_case_						       =	0
		while n % i == 0:
			n //= i
			multiplicity += 1
		divisors_count *= multiplicity + 1
		i += 1
	if n > 1:
		divisors_count *= 2
	return divisors_count


def 		lowerCamelCase__       (						):







	'''simple docstring'''





	return next(i for i in triangle_number_generator() if count_divisors(_A				) > 500				)


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