from qiskit import *
%matplotlib inline
from qiskit.tools.visualization import plot_histogram

secretnumber='101001'

circuit=QuantumCircuit(len(secretnumber)+1,len(secretnumber))

# circuit.h([0,1,2,3,4,5])
# circuit.x(6)
# circuit.h(6)
circuit.h(range(len(secretnumber)))
circuit.x(len(secretnumber))
circuit.z(len(secretnumber))

circuit.draw(output='mpl')

circuit.barrier()

for i,check in enumerate(reversed(secretnumber)):
    if check == '1':
        circuit.cx(i,len(secretnumber))
        

# circuit.cx(5,6)
# circuit.cx(2,6)
# circuit.cx(0,6)

circuit.draw(output='mpl')

circuit.barrier()

circuit.h(range(len(secretnumber)))

circuit.draw(output='mpl')

circuit.measure(range(len(secretnumber)),range(len(secretnumber)))

circuit.draw(output='mpl')

simulator=Aer.get_backend('qasm_simulator')
result=execute(circuit,backend=simulator,shots=1).result()
count=result.get_counts()

print(count)

