%matplotlib inline
# Importing standard Qiskit libraries
from qiskit import QuantumCircuit, execute, Aer, IBMQ
from qiskit.compiler import transpile, assemble
from qiskit.tools.jupyter import *
from random import randint
import hashlib

#Alice cell, Bob can't see what's going in on here
m0 = randint(0,1)
Alice_base = randint(0,1)
qubits = list()
mycircuit = QuantumCircuit(1,1)
if(Alice_base == 0):
    if(m0 == 1):
        mycircuit.x(0)
else:
    if(m0 == 0):
        mycircuit.h(0)
    else:
        mycircuit.x(0)
        mycircuit.h(0)
qubits.append(mycircuit)

#Bob cell, Alice can't see what's going in on here
backend = Aer.get_backend('qasm_simulator')
a = 0
qubit = qubits[0]
if(Alice_base == 0):
    qubit.measure(0,0)
else:
    qubit.h(0)
    qubit.measure(0,0)
result = execute(qubit, backend, shots=1, memory=True).result()
a = int(result.get_memory()[0])

#Bob cell, Alice can't see what's going in on here
m1 = randint(0,1)
Bob_base = randint(0,1)
qubitsB = list()
mycircuitB = QuantumCircuit(1,1)
if(Bob_base == 0):
    if(m1 == 1):
        mycircuitB.x(0)
else:
    if(m1 == 0):
        mycircuitB.h(0)
    else:
        mycircuitB.x(0)
        mycircuitB.h(0)
qubitsB.append(mycircuitB)

#Alice cell, Bob can't see what's going in on here
backend = Aer.get_backend('qasm_simulator')
b = 0
qubit = qubitsB[0]
if(Bob_base == 0):
    qubit.measure(0,0)
else:
    qubit.h(0)
    qubit.measure(0,0)
result = execute(qubit, backend, shots=1, memory=True).result()
b = int(result.get_memory()[0])

#Alice cell, Bob can't see what's going in on here
print("The result of the coin flip was: " + str(b ^ m0))

#Bob cell, Alice can't see what's going in on here
print("The result of the coin flip was: " + str(m1 ^ a))