Qiskit code for the BB84 algorithm
Our BB84 simulation is a 150-line program (give or take a few lines). To make the program comprehensible, we’ll divide it into 16 function definitions. Let’s start with the imports and constant declarations:
import randomfrom qiskit import QuantumCircuit, QuantumRegister, \ ClassicalRegister, Aer, execute NUMBER_OF_CIRCUITS = 100 DOES_EVE_EXIST = False CHECK_MARK = u'\u2713'
According to these declarations, we’ll be creating 100
circuits – one for each of the qubits that Alice sends to Bob. We’ll simulate a situation in which no eavesdropper exists. For convenience, we will declare CHECK_MARK
to be the Unicode symbol.
The main flow of execution looks like this:
circuits = create_circuits(NUMBER_OF_CIRCUITS, DOES_EVE_EXIST...