import unittest

import cirq
import random
import numpy as np

import hypothesis.strategies as st
from hypothesis import given, settings

def create_bell_pair(qubits):
    qc = cirq.Circuit() 
    qc.append(cirq.H(qubits[1]))
    qc.append(cirq.CNOT(qubits[1],qubits[0]))
    return qc

def encode_message(qc, qubit, msg):
    if len(msg) != 2 or not set([0,1]).issubset({0,1}):
        raise ValueError(f"message '{msg}' is invalid")
    if msg[1] == "1":
        qc.append(cirq.X(qubit))
    if msg[0] == "1":
        qc.append(cirq.Z(qubit))
    return qc

def decode_message(qc, qubits):
    qc.append(cirq.CNOT(qubits[1],qubits[0]))
    qc.append(cirq.H(qubits[1]))
    return qc

qubits = cirq.LineQubit.range(2)
qc = create_bell_pair(qubits)

message = '11'    
    
qc = encode_message(qc, qubits[1], message)

qc = decode_message(qc, qubits)

qc.append(cirq.measure(*qubits, key='m'))

print(qc)

simulator = cirq.Simulator()
results = simulator.run(qc , repetitions =1)
readings = np.array2string(results.measurements['m'][0], separator='')[1:-1][::-1]
print(readings)

