import cirq

## Function for visualizing output
def bitstring(bits):
    return ''.join('1' if e else '0' for e in bits)

## Create two quantum and classical registers
qreg = [cirq.LineQubit(x) for x in range(2)]
circuit = cirq.Circuit()

message = {"00" : [],
          "10" : [cirq.X(qreg[0])],
          "01" : [cirq.Z(qreg[0])],
          "11" : [cirq.X(qreg[0]), cirq.Z(qreg[0])]}

## Creating a bell pair
circuit.append(cirq.H(qreg[0]))
circuit.append(cirq.CNOT(qreg[0], qreg[1]))

m = "10"
print("Alice sent a message")

## Encodding the message in qubits
circuit.append(message[m])

## Bob is trying to decode
circuit.append(cirq.CNOT(qreg[0], qreg[1]))
circuit.append(cirq.H(qreg[0]))
circuit.append([cirq.measure(qreg[0]), cirq.measure(qreg[1])])

print("\n Circuit is :")
print(circuit)

sim = cirq.Simulator()
res = sim.run(circuit, repetitions = 1)

print("BOB recieved message: ",bitstring(res.measurements.values())) 