



"""simple docstring"""


import qiskit

def 			_lowerCAmelCase				(       lowercase_		,     lowercase_						):
						UpperCAmelCase					=			qiskit.Aer.get_backend('aer_simulator'						)

						UpperCAmelCase					=			qiskit.QuantumCircuit(4		,     2						)
						# encode inputs in qubits 0 and 1
						if bita == 1:
												qc_ha.x(0						)
						if bita == 1:
												qc_ha.x(1						)
						qc_ha.barrier()

						# use cnots to write XOR of the inputs on qubit2
						qc_ha.cx(0		,     2						)
						qc_ha.cx(1		,     2						)

						# use ccx / toffoli gate to write AND of the inputs on qubit3
						qc_ha.ccx(0		,     1		,     3						)
						qc_ha.barrier()

						# extract outputs
						qc_ha.measure(2		,     0						)  # extract XOR value
						qc_ha.measure(3		,     1						)  # extract AND value

						# Execute the circuit on the qasm simulator
						UpperCAmelCase					=			qiskit.execute(lowercase_		,     lowercase_		,     shots=1000						)

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


if __name__ == "__main__":
				snake_case_    					=	half_adder(1, 1)
				print(f'''Half Adder Output Qubit Counts: {counts}''')










"""simple docstring"""


import os
import random
import sys

from . import cryptomath_module as cryptomath
from . import rabin_miller

snake_case_    					=	3

def 			_lowerCAmelCase				(       lowercase_						):
						print('Generating primitive root of p'						)
						while True:
												UpperCAmelCase					=			random.randrange(3		,     lowercase_						)
												if pow(lowercase_		,     2		,     lowercase_						) == 1:
																		continue
												if pow(lowercase_		,     lowercase_		,     lowercase_						) == 1:
																		continue
												return g

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

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

						return public_key, private_key

def 			_lowerCAmelCase				(       lowercase_		,     lowercase_						):
						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				,   UpperCAmelCase					=			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'		,     2048						)
						print('Key files generation successful'						)


if __name__ == "__main__":
				main()





