|
EnigmaMachineCore 0.1.0
A modular Enigma Machine simulation in C++20
|
This project uses GoogleTest (gTest) for unit testing and CTest as the test runner.
The project follows a "centralized mirror" strategy:
tests/ directory.tests/ strictly mirrors the structure of the project's source code.EnigmaCore static library, allowing them to test the logic without the application's main() function interfering.By default, tests are disabled to maintain fast build times for the core application. You must explicitly enable them during the CMake configuration step:
Navigate to your build directory (usually build/debug) and use ctest:
Ctrl+Shift+P -> Run Task -> Run Tests.F5.Add a new .cpp file in the appropriate subdirectory within tests/. Use the GoogleTest macros:
Open tests/CMakeLists.txt and add your new file to the add_executable(EnigmaTests ...) list:
Re-run your build command. CMake will automatically detect the new tests.
To ensure cryptographic accuracy, the project includes a suite of tests based on historical Enigma I (Wehrmacht/Luftwaffe) configurations. These tests use verified wiring and notch data found in assets/historical/.
| Test Name | Description | Source |
|---|---|---|
StandardAAAAA_BDZGO | Validates the classic "AAAAA" vector for Rotors I-II-III. | Historical Baseline |
OCAMLVector | Complex setup with plugboard and custom starting positions. | Cornell CS 3110 |
LongStringVerification | Verifies stepping logic over a 35-character string. | EnigmaCore Baseline |
HistoricalReciprocity | Ensures encryption/decryption symmetry with historical settings. | - |
These tests are located in tests/EnigmaMachine/TestHistoricalVectors.cpp.
To improve code reliability and detect memory errors or undefined behavior, the project integrates LLVM/Clang Sanitizers.
clang / clang++ must be used for sanitizer builds.You can enable sanitizers individually during the CMake configuration step:
| Option | Sanitizer | Description |
|---|---|---|
ENIGMA_USE_ASAN | AddressSanitizer (ASan) | Detects heap/stack buffer overflows, use-after-free, and memory leaks. |
ENIGMA_USE_UBSAN | UndefinedBehaviorSanitizer (UBSan) | Detects signed integer overflow, null pointer dereference, and other C++ undefined behaviors. |
ENIGMA_USE_MSAN | MemorySanitizer (MSan) | Detects uninitialized memory reads. |
Example Command:
To run the same scenarios as the CI locally, use the provided helper script:
The project includes a custom CMake target to run the entire test suite through Valgrind.
bash cmake -DENIGMA_BUILD_TESTS=ON -S . -B build bash cmake --build build --target Enigma_valgrind This will execute EnigmaTests with --leak-check=full and will return a non-zero exit code if any leaks or memory errors are detected, making it suitable for both local development and CI gates.
Code analysis is centralized in the Code Analysis workflow (code-analysis.yml), which runs on every push and pull request. It orchestrates parallel jobs for:
sanitizers.yml workflow.Results are aggregated into a single GitHub Job Summary without failing the build, allowing the team to monitor and fix issues asynchronously.
The project uses CMake's FetchContent to download GoogleTest automatically.
build/<build_type>/_deps and can be used offline.The project uses RapidCheck for property-based testing, which generates random test cases to verify fundamental cryptographic properties across thousands of configurations.
Unlike traditional unit testing with fixed inputs, property-based testing randomly generates inputs and verifies that certain mathematical properties hold. For the Enigma machine, the most important property is reciprocity: encrypting then decrypting with the same settings must return the original value.
Property tests are disabled by default. To enable them:
The property-based test suite includes 60+ tests across 5 test modules:
| Module | Tests | Key Properties Verified |
|---|---|---|
EnigmaMachineProperties | 10 | Reciprocity, Decryption symmetry, Output range |
RotorProperties | 14 | Forward/reverse transform inverse, Rotation cycles |
PlugBoardProperties | 15 | Swapping symmetry, No fixed points, Determinism |
ReflectorProperties | 5 | Bidirectional mapping, No self-mapping |
RotorBoxProperties | 14 | Multi-rotor stepping, Full encryption cycle |
Encrypt(Encrypt(x)) == x - The fundamental Enigma propertyProperty tests run automatically on every push and pull request via the test-and-coverage.yml workflow. The job includes:
For code coverage analysis (gcov/lcov), thresholds, and CI integration, see Benchmarking Guide.