## e91 protocol

The E91 protocol proposed by Artur Ekert in 1991 is another QKD protocol that allows two parties to securely establish a shared secret key. The protocol is based on the entanglement of two particles, such as photons, in a Bell state.

The sender randomly chooses one of four possible measurements to make on their particle, and the receiver randomly chooses one of two possible measurements to make on their particle. The sender and receiver then compare their measurement results and use them to establish the secret key. Any attempt by an eavesdropper to measure or intercept one of the entangled particles will necessarily disturb the other particle, and this will be detected by the sender and receiver, ensuring the security of the communication.

` ````
```
# Import necessary libraries
from qiskit import QuantumCircuit, Aer, execute
from qiskit.tools.visualization import plot_histogram
# Define the quantum circuit with 3 qubits and 3 classical bits
qc = QuantumCircuit(3, 3)
# Alice generates a pair of entangled photons
qc.h(0)
qc.cx(0, 1)
# Alice chooses a random sequence of bases to measure her photon
alice_bases = [0, 1, 0] # Example random sequence of bases
# Alice measures her photon in the chosen bases
for i in range(3):
if alice_bases[i] == 0: # Horizontal/vertical basis
qc.h(i)
else: # Diagonal/anti-diagonal basis
qc.rx(pi/4, i) # Rotate qubit by pi/4 around the x-axis
qc.h(i)
qc.measure(i, i)
# Alice publicly announces her bases
# Bob chooses a random sequence of bases to measure his photon
bob_bases = [1, 0, 1] # Example random sequence of bases
# Bob measures his photon in the chosen bases
for i in range(3):
if bob_bases[i] == 0: # Horizontal/vertical basis
qc.h(i)
else: # Diagonal/anti-diagonal basis
qc.rx(pi/4, i) # Rotate qubit by pi/4 around the x-axis
qc.h(i)
qc.measure(i, i)
# Bob publicly announces his bases
# Alice and Bob compare their bases and discard any measurements made in different bases
discard_indices = []
for i in range(3):
if alice_bases[i] != bob_bases[i]:
discard_indices.append(i)
qc.barrier()
qc.measure(range(3), range(3)) # Measure all qubits again to get key bits
# Alice and Bob compare their key bits to check for errors and establish the secret key
results = execute(qc, Aer.get_backend('qasm_simulator'), shots=1).result().get_counts()
alice_key = [int(bit) for bit in list(results.keys())[0]]
bob_key = [int(bit) for bit in list(results.keys())[0]]
for i in discard_indices:
alice_key.pop(i)
bob_key.pop(i)
if alice_key == bob_key:
print("Secret key established:", alice_key)
else:
print("Error detected.")
# Plot the final state of the qubits
plot_histogram(results)

This code implements the E91 protocol, which is a quantum key distribution protocol used to establish a secret key between two parties, Alice and Bob, over an insecure channel. The protocol involves the use of entangled qubits and the measurement of those qubits in different bases.

The code begins by importing necessary libraries and defining a quantum circuit with three qubits and three classical bits using the Qiskit framework.

In the protocol, Alice generates a pair of entangled photons, and in this code, this is achieved by applying a Hadamard gate (qc.h(0)) and a controlled-NOT gate (qc.cx(0,1)) on the first two qubits, where the first qubit belongs to Alice and the second qubit belongs to Bob. This generates an entangled pair of photons, where the state of one photon is dependent on the state of the other photon.

Alice then chooses a random sequence of bases to measure her photon and measures her photon in the chosen bases. The bases can be either the horizontal/vertical basis (0) or the diagonal/anti-diagonal basis (1). In this code, Alice’s measurement basis is determined by the list alice_bases.

Similarly, Bob also chooses a random sequence of bases to measure his photon and measures his photon in the chosen bases. Bob’s measurement basis is determined by the list bob_bases.

After the measurements, Alice and Bob publicly announce their bases and compare their bases. They discard any measurements made in different bases and measure all qubits again to get key bits. The indices corresponding to measurements made in different bases are stored in discard_indices list.

Finally, Alice and Bob compare their key bits to check for errors and establish the secret key. If there are no errors, the code prints “Secret key established” and displays a histogram of the final state of the qubits. If there are errors, the code prints “Error detected.”

Note that, as which BB84 protocol, this is just a simplified pseudo-code implementation and does not include all the necessary error correction and privacy amplification techniques that are commonly used in practical QKD systems.