# Scenario 1: Perfect Channel (No Eavesdropping)
results_no_eve <- run_bb84_simulation(eavesdropping_active = FALSE)
cat("--- Scenario 1: No Eavesdropping ---\n")
cat(paste("Sifted Key Length:", results_no_eve$Sifted_Length, "\n"))
cat(paste("Final Key Length:", results_no_eve$Final_Key_Length, "\n"))
cat(paste("Quantum Bit Error Rate (QBER):", round(results_no_eve$QBER * 100, 2), "%\n"))
cat("Result: Secure key established successfully.\n")
# Scenario 2: Measure-and-Resend Attack
results_with_eve <- run_bb84_simulation(eavesdropping_active = TRUE)
cat("\n--- Scenario 2: With Eavesdropping ---\n")
cat(paste("Sifted Key Length:", results_with_eve$Sifted_Length, "\n"))
cat(paste("Final Key Length:", results_with_eve$Final_Key_Length, "\n"))
cat(paste("Quantum Bit Error Rate (QBER):", round(results_with_eve$QBER * 100, 2), "%\n"))
if (results_with_eve$QBER > 0.15) {
cat("High QBER detected. Eavesdropping likely — key discarded.\n")
} else {
cat("No eavesdropping detected (unlikely in theory).\n")
}
Run the code above in your browser using DataLab