Implementing the no encryption protocol simulation
To establish a baseline for comparison in my quantum cryptography simulator, I implemented a NoEncryption class. This class represents a scenario where a cryptographic key is used (specifically for a one-time pad operation inherited from the base class), but there’s no secure mechanism for exchanging or agreeing upon that key. It inherits from the EncryptionBase abstract class I previously developed.
The NoEncryption Class
This class provides a concrete implementation for the abstract methods defined in EncryptionBase.
from types import SimpleNamespace
from .encryption_base import EncryptionBase
import numpy as np
class NoEncryption(EncryptionBase):
def __init__(self, s: SimpleNamespace):
super().__init__()
# Store configuration specific to this protocol
self._cfg = s
self._protocol = 'No Protocol'
def generateKey(self, seed: int = None):
# Optionally set seed for reproducible 'random' key
if seed is not None:
np.random.seed(seed)
# Generate random bits using NumPy
bits = np.random.randint(0, 2, self._cfg.KEY_LENGTH, dtype=np.uint8)
# Pack bits into bytes to form the key
self._key = np.packbits(bits).tobytes()
# Mark key as 'valid' immediately after generation
self._isKeyValid = True
def reconcileKey(self, key):
# In this 'No Protocol' simulation, reconciliation is trivial.
# We assume the key is somehow known and just mark it valid.
self._isKeyValid = True
In this implementation:
- The
__init__method takes configuration parameters (likeKEY_LENGTH) specific to this non-protocol. generateKeycreates a key usingnumpy.random.randint. It simulates having a key but without any secure distribution process. The key is considered valid immediately. Aseedcan be provided for deterministic key generation, useful for testing.reconcileKeyis minimal; it simply sets the_isKeyValidflag toTrue. This reflects the core idea of this simulation mode: there’s no actual reconciliation or security check involved in establishing the key between parties. Alice generates it, and Bob (and potentially Eve) are assumed to magically possess it.- The actual encryption and decryption rely on the
encryptanddecryptmethods inherited fromEncryptionBase, which perform the XOR-based one-time pad operation.
Unit Testing NoEncryption
To ensure the class functions as expected, I wrote unit tests using Python’s built-in unittest framework.
These tests verify:
- the protocol identifier is correct,
- key generation produces consistent results when seeded,
- the
_isKeyValidflag is managed correctly, - the encryption/decryption cycle successfully recovers the original message using the inherited one-time pad logic.
This NoEncryption class serves as a simple baseline. It uses a potentially strong encryption algorithm (OTP) but lacks any secure key exchange, making it vulnerable if the key is intercepted, which is precisely what the simulation aims to demonstrate when eavesdropping is enabled.
For access to the complete simulation code, please visit the GitHub repository here.