- Wait for a request from one node
- Tells him that will be the master(1)
- Receive the qubits from the first node
- Wait for a request from the second node
- Tells him that will not be the master(1)
- Receive the qubits from the second node
- Apply a cNOT on every qubit using the master's qubits as controller and the other node's qubits as target (2)
- Apply the Hadamard to every qubit of the master (3)
- Measure the qubits and send the results as an array of pairs to both the first and second node via a classical channel
- Generate two array (
x_vector
andh_vector
) of random classical bits - Generate an array of qubits
q_vector
using the two classical vectors(4) - Send a request to Charlie
- Receive if it will be the master
- Send the qubits to Charlie
- Wait for the matrix from Charlie
- Exchange the
h_vector
with the other node - If the node is master it filters the
x_vector
in order to obtain the actual key(5) - Otherwise it cleans the unusable bits from the
x_vector
(6) - Create a
key
array and fill it with valid bits fromx_vector
(7)
(1) master: the node who flips the bits to recover the correct key
(2) Charlie's cNOT operation:
first_node_qubits[i].cnot(second_node_qubits[i])
(3) Charlie's Hadamard operation:
first_node_qubits[i].H()
(4) generation of the qubits:
if x_vector[i] == 1:
q_vector[i].X() # Applies the X Gate
if h_vector[i] == 1:
q_vector.H() # Applies the Hadamard Gate
(5) filtering of the x_vector
:
if matrix[i][1] == 0:
x_vector[i] = "b"
continue
if h_vector[i] != hother_vector[i]:
x_vector[i] = "h"
continue
if h_vector[i] == 1 and matrix[i][0] == 0:
continue
x_vector[i] = 1 if x_vector[i] == 0 else 0
(6) unusable bits removal from x_vector
:
if matrix[i][1] == 0:
x_vector[i] = "b"
continue
if h_vector[i] != hother_vector[i]:
x_vector[i] = "h"
continue
(7) key finalization:
if type(x_vector[i]) is not str:
key.append(x_vector[i])