import qiskit as q
%matplotlib inline

from qiskit import *
from qiskit.visualization import plot_bloch_multivector, visualize_transition, plot_histogram

Msg = "QuantumComputing"
secretnum = ''.join(format(ord(i), 'b') for i in Msg)

# printing result
print("The string after binary conversion : " + str(secretnum))

print("Your Quantum Algorithm is Running!")
circuit = q.QuantumCircuit(len(secretnum)+1, len(secretnum))

circuit.h(range(len(secretnum)))

circuit.x(len(secretnum))
circuit.h(len(secretnum))
circuit.barrier()

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

circuit.barrier()

circuit.h(range(len(secretnum)))
circuit.barrier()

circuit.measure(range(len(secretnum)),range(len(secretnum)))
circuit.barrier()

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

counts = str(counts)
counts = (counts[2:len(secretnum)+2])
print("the binary of ur String is", counts)

def BinaryToDecimal(binary): 
	string = int(binary, 2) 
	return string 

bin_data = str(counts)

str_data =' '

for i in range(0, len(bin_data), 7): 
	temp_data = bin_data[i:i + 7]  
	decimal_data = BinaryToDecimal(temp_data) 
	str_data = str_data + chr(decimal_data) 

# printing the result 
print("The Binary value after string conversion is:", str_data) 