# Estimating Interception Density in the BB84 Protocol: A Study with a Noisy Quantum Simulator
## 4 BB84 Simulation Model
### Key Generation  
The initial phase of the program, depicted in Figure 2, is responsible for generating the cryptographic key. When initiating the program, the available inputs that can be chosen include the following:  
* Input string length: In our modified version of the simulator, this parameter exactly corresponds to \(n\), the number of bits initially exchanged during the QKD process.
* Interception density: This refers to the percentage of qubits that [PERSON] may intercept and forward to [PERSON]. It quantifies [PERSON]'s ability to eavesdrop on the qubit transmission between [PERSON] and [PERSON], hence influencing the overall security and effectiveness of the key distribution process.
* Backend: The IBM backend simulator to be used in receiving operations for decoding bits.  
The program then initiates with [PERSON] generating a binary array of length \(n\), corresponding to the random transmission \"axes\" (i.e., bases). Additionally, she randomly generates the \(n\) bits to be exchanged with [PERSON] to establish the secret key. For each bit, the associated quantum state is determined based on the corresponding random basis and the mapping strategy, as shown in Table 1 and as explained below.  
The simulation of the qubit encryption process on quantum hardware begins by looping the number of times specified by the parameter \(n\) to encode each bit. Accordingly, if the qubit's state is 1, the X gate is applied. Otherwise, the qubit is skipped to the next step. Similarly, if the corresponding basis value is \(X\) (i.e., \"diagonal\"), the H gate is applied. Otherwise, no action is taken. Following this step, the qubit has been encrypted, and the  
Figure 1: BB84 flowchart.  
next one can begin the same encryption process. Once all the qubits from the [PERSON] \(n-\)long array have been encrypted, they can be transmitted to [PERSON].  
Before reaching [PERSON], [PERSON] may attempt to intercept the transmitted qubits. She is equipped with an array of \(n\) randomly generated bits, which serve as her basis values. As with [PERSON], she will loop \(n\) times and attempt to guess the received bit. More specifically, the program randomly generates a number between 0 and 1, and if it is smaller than the interception density chosen as input, then [PERSON] is successful in intercepting the qubit. Subsequently, the qubit is eventually subjected to an H gate operation if the corresponding basis is the \"diagonal\" one, or otherwise, no other operation is performed. Now the process continues by effectively measuring the intercepted qubit (by performing the Qiskit measure operation) and by decoding the corresponding bit value through the readout operation of the backend simulator (selected at the start of the program). Once all the intercepted qubits have been processed, they are forwarded to [PERSON].  
[PERSON]'s behavior is essentially identical to that of [PERSON], differing only in his interception density value, which is 1, since he intercepts all the qubits sent by [PERSON] and [PERSON]. Subsequently, [PERSON] decodes the \(n\) received qubits by applying the same operations as [PERSON], based on the values of his random bases array. Upon completion, he publicly announces that [PERSON]'s message has been received.  
Upon receipt of the message, both [PERSON] and [PERSON] can securely share their bases. By doing so, they can compare the bases and keep only the bit values in which the bases are the same. Such remaining \(k\) bits will be used to subsequently form the private key, which will be verified in the following step.