
"""simple docstring"""







import os
import random
import sys

from . import cryptomath_module as cryptomath
from . import rabin_miller

lowerCamelCase__        =		3
def    __lowerCAmelCase    (_UpperCamelCase		):
	print('Generating primitive root of p'		)
	while True:
		__lowerCAmelCase      :						Optional[Any]						      =				random.randrange(3	,  _UpperCamelCase		)
		if pow(_UpperCamelCase	,  2	,  _UpperCamelCase		) == 1:
			continue
		if pow(_UpperCamelCase	,  _UpperCamelCase	,  _UpperCamelCase		) == 1:
			continue
		return g
def    __lowerCAmelCase    (_UpperCamelCase		):
	print('Generating prime p...'		)
	__lowerCAmelCase      :						int						      =				rabin_miller.generate_large_prime(_UpperCamelCase		)  # select large prime number.
	__lowerCAmelCase      :						str						      =				primitive_root(_UpperCamelCase		)  # one primitive root on modulo p.
	__lowerCAmelCase      :						Tuple						      =				random.randrange(3	,  _UpperCamelCase		)  # private_key -> have to be greater than 2 for safety.
	__lowerCAmelCase      :						Tuple						      =				cryptomath.find_mod_inverse(pow(_UpperCamelCase	,  _UpperCamelCase	,  _UpperCamelCase		)	,  _UpperCamelCase		)

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

	return public_key, private_key
def    __lowerCAmelCase    (_UpperCamelCase	,  _UpperCamelCase		):




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

	__lowerCAmelCase      ,       __lowerCAmelCase      :						Optional[int]						      =				generate_key(_UpperCamelCase		)
	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'	,  2048		)
	print('Key files generation successful'		)


if __name__ == "__main__":
					main()

"""simple docstring"""







import qiskit
def    __lowerCAmelCase    (_UpperCamelCase	,  _UpperCamelCase		):
	__lowerCAmelCase      :						Union[str, Any]						      =				qiskit.Aer.get_backend('aer_simulator'		)

	# Create a Quantum Circuit acting on the q register
	__lowerCAmelCase      :						str						      =				qiskit.QuantumCircuit(_UpperCamelCase	,  _UpperCamelCase		)

	# Map the quantum measurement to the classical bits
	circuit.measure([0]	,  [0]		)

	# Execute the circuit on the simulator
	__lowerCAmelCase      :						Optional[int]						      =				qiskit.execute(_UpperCamelCase	,  _UpperCamelCase	,  shots=1000		)

	# Return the histogram data of the results of the experiment.
	return job.result().get_counts(_UpperCamelCase		)


if __name__ == "__main__":
							print(f'Total count for various states are: {single_qubit_measure(1, 1)}')