Learn R Programming

qvirus (version 0.0.5)

run_e91_simulation: E91 Quantum Key Distribution (QKD) Simulation

Description

Simulates the E91 (Ekert 1991) quantum key distribution protocol using entangled particle pairs (EPR) and Bell’s theorem (CHSH statistic) to ensure channel security. Security is established when the Bell Inequality is violated, i.e. when \(|S| > 2\), indicating quantum behavior.

Usage

run_e91_simulation(
  eavesdropping_active = FALSE,
  key_length = 1000,
  noise_level = 0.5
)

Value

A list of class "E91Simulation" containing:

S_Calculated

Observed Bell CHSH statistic.

S_Theoretical

Quantum theoretical value (\(\approx\) -2.8284).

Bell_Violation

TRUE if \(|S| > 2\) (secure), FALSE if \(|S| \leq 2\) (insecure).

Sifted_Key_Length

Number of bits retained for key formation.

Eavesdropping

Indicates if an attack was simulated.

Arguments

eavesdropping_active

Logical. If TRUE, the entanglement is partially destroyed, simulating an attack that forces the system toward the classical limit where \(|S| \leq 2\). Default is FALSE.

key_length

Integer. Number of simulated EPR pairs (default = 1000).

noise_level

Numeric. Noise level (0-1) applied when eavesdropping_active = TRUE, reducing quantum correlation. A value of 0.5 represents partial decoherence. Default is 0.5.

Details

El E91 se diferencia de BB84 en que la detección del espía es simultánea a la generación de la clave. Los pares de bases son separados en dos conjuntos:

  1. Clave Secreta: Pares con perfecta anti-correlación (ej. a2-b1, a3-b2).

  2. Test de Bell: Pares restantes usados para calcular la esperanza $E(a_i, b_j)$ y el valor $S$.

Si $S$ cae por debajo de 2 (límite clásico de Bell), se concluye que el entrelazamiento ha sido roto por Eve, y la clave debe descartarse.

References

Ekert, A. K. (1991). Quantum cryptography based on Bell's theorem. Physical Review Letters, 67(6), 661.

Examples

Run this code
# Escenario 1: Canal Cuántico Seguro (No Eavesdropping)
results_secure <- run_e91_simulation(eavesdropping_active = FALSE)
cat("--- Escenario 1: Sin Eavesdropping ---\n")
cat(paste("S Calculado:", round(results_secure$S_Calculated, 4), "\n"))
cat(paste("Violación de Bell:", results_secure$Bell_Violation, "\n"))

# Escenario 2: Ataque que Rompe el Entrelazamiento
results_attack <- run_e91_simulation(eavesdropping_active = TRUE)
cat("\n--- Escenario 2: Con Ataque ---\n")
cat(paste("S Calculado:", round(results_attack$S_Calculated, 4), "\n"))
cat(paste("Violación de Bell:", results_attack$Bell_Violation, "\n"))

Run the code above in your browser using DataLab