|
EnigmaMachineCore 0.1.0
A modular Enigma Machine simulation in C++20
|
Class representing the Enigma machine. More...
#include <EnigmaMachine.hpp>
Inheritance diagram for EnigmaMachine:
Collaboration diagram for EnigmaMachine:Public Member Functions | |
| EnigmaMachine (ILogger *logger=nullptr) | |
| Default Constructor. Initializes a standard Enigma Machine (3 Rotors, standard Reflector). | |
| EnigmaMachine (const IAssetProvider &provider, std::string_view fileName, std::string_view assetPath="", ILogger *logger=nullptr) | |
| File-based Constructor using a specific Asset Provider. | |
| EnigmaMachine (std::string_view fileName, std::string_view assetPath="", ILogger *logger=nullptr) | |
| File-based Constructor. Initializes the machine by parsing a TOML configuration file from the filesystem. | |
| ~EnigmaMachine () override | |
| EnigmaMachine (const EnigmaMachine &)=delete | |
| EnigmaMachine & | operator= (const EnigmaMachine &)=delete |
| EnigmaMachine (EnigmaMachine &&other) noexcept | |
| EnigmaMachine & | operator= (EnigmaMachine &&other) noexcept |
| AlphabetIndex | keyTransform (AlphabetIndex input) |
| Transforms the input key through the rotor box. | |
| void | processBuffer (std::span< AlphabetIndex > buffer) |
| Processes a buffer of alphabet indexes in-place. | |
| void | setLogger (ILogger *logger) |
| Sets the logger for the machine. | |
| void | registerObserver (IEnigmaObserver *observer) |
| Registers an observer to receive notifications. | |
| void | removeObserver (IEnigmaObserver *observer) |
| Removes an observer. | |
| void | onRotorStepped (int rotorIndex, AlphabetIndex position) override |
| Called when a rotor steps. | |
| void | onCharEncrypted (char input, char output) override |
| Called when a character is encrypted/decrypted. | |
Public Member Functions inherited from IEnigmaObserver | |
| virtual | ~IEnigmaObserver () |
Protected Member Functions | |
| EnigmaMachine (const EnigmaMachineConfig &config, ILogger *logger=nullptr) | |
| Internal constructor using the configuration struct. Accessible to tests and benchmarks, but hidden from the public API. | |
| EnigmaMachine (EnigmaMachineConfig &&config, ILogger *logger=nullptr) | |
| Internal constructor using the configuration struct (move version). | |
Private Attributes | |
| std::unique_ptr< RotorBox > | rotorBox |
| std::unique_ptr< PlugBoard > | plugBoard |
| std::vector< IEnigmaObserver * > | observers |
| ILogger * | logger = nullptr |
Class representing the Enigma machine.
This class encapsulates the functionality of the Enigma machine, providing a simple interface for encryption while hiding the complexity of the rotors and plugboard.
Definition at line 31 of file EnigmaMachine.hpp.
|
explicitprotected |
Internal constructor using the configuration struct. Accessible to tests and benchmarks, but hidden from the public API.
| config | The machine configuration. |
| logger | Optional logger for event reporting. |
Definition at line 74 of file EnigmaMachine.cpp.
References rotorBox.
|
explicitprotected |
Internal constructor using the configuration struct (move version).
| config | The machine configuration. |
| logger | Optional logger for event reporting. |
Definition at line 81 of file EnigmaMachine.cpp.
References rotorBox.
|
explicit |
Default Constructor. Initializes a standard Enigma Machine (3 Rotors, standard Reflector).
| logger | Optional logger for event reporting. |
Definition at line 49 of file EnigmaMachine.cpp.
References defaultReflectorFile, defaultRotor1File, defaultRotor2File, defaultRotor3File, EnigmaConfigLoader::loadReflector(), EnigmaConfigLoader::loadRotor(), logger, plugBoard, resolveDefaultAssetPath(), and rotorBox.
Here is the call graph for this function:| EnigmaMachine::EnigmaMachine | ( | const IAssetProvider & | provider, |
| std::string_view | fileName, | ||
| std::string_view | assetPath = "", |
||
| ILogger * | logger = nullptr |
||
| ) |
File-based Constructor using a specific Asset Provider.
| provider | The asset provider to use for loading configuration. |
| fileName | The path to the TOML configuration file. |
| assetPath | Optional base directory for assets. |
| logger | Optional logger for event reporting. |
Definition at line 70 of file EnigmaMachine.cpp.
|
explicit |
File-based Constructor. Initializes the machine by parsing a TOML configuration file from the filesystem.
| fileName | The path to the TOML configuration file. |
| assetPath | Optional base directory for assets. |
| logger | Optional logger for event reporting. |
Definition at line 89 of file EnigmaMachine.cpp.
|
overridedefault |
|
delete |
|
noexcept |
Definition at line 94 of file EnigmaMachine.cpp.
References removeObserver().
Here is the call graph for this function:| AlphabetIndex EnigmaMachine::keyTransform | ( | AlphabetIndex | input | ) |
Transforms the input key through the rotor box.
| input | The input key to be transformed. |
The transformation follows the historic Enigma signal path:
Definition at line 129 of file EnigmaMachine.cpp.
References onCharEncrypted(), plugBoard, and rotorBox.
Referenced by processBuffer(), and processMessage().
Here is the call graph for this function:
Here is the caller graph for this function:
|
overridevirtual |
Called when a character is encrypted/decrypted.
| input | The original input character. |
| output | The final output character. |
Implements IEnigmaObserver.
Definition at line 166 of file EnigmaMachine.cpp.
References observers.
Referenced by keyTransform().
Here is the caller graph for this function:
|
overridevirtual |
Called when a rotor steps.
| rotorIndex | The index of the rotor (0 is the rightmost/fastest). |
| position | The new position of the rotor (0-25). |
Implements IEnigmaObserver.
Definition at line 160 of file EnigmaMachine.cpp.
References observers.
|
delete |
|
noexcept |
Definition at line 105 of file EnigmaMachine.cpp.
| void EnigmaMachine::processBuffer | ( | std::span< AlphabetIndex > | buffer | ) |
Processes a buffer of alphabet indexes in-place.
| buffer | The span of characters to transform. |
Definition at line 140 of file EnigmaMachine.cpp.
References keyTransform().
Here is the call graph for this function:| void EnigmaMachine::registerObserver | ( | IEnigmaObserver * | observer | ) |
Registers an observer to receive notifications.
| observer | The observer to register. |
Definition at line 151 of file EnigmaMachine.cpp.
References observers.
Referenced by runApplication().
Here is the caller graph for this function:| void EnigmaMachine::removeObserver | ( | IEnigmaObserver * | observer | ) |
Removes an observer.
| observer | The observer to remove. |
Definition at line 153 of file EnigmaMachine.cpp.
References observers.
Referenced by EnigmaMachine().
Here is the caller graph for this function:| void EnigmaMachine::setLogger | ( | ILogger * | logger | ) |
Sets the logger for the machine.
| logger | The logger to use. |
Definition at line 144 of file EnigmaMachine.cpp.
|
private |
Definition at line 52 of file EnigmaMachine.hpp.
Referenced by EnigmaMachine(), and setLogger().
|
private |
Definition at line 51 of file EnigmaMachine.hpp.
Referenced by onCharEncrypted(), onRotorStepped(), registerObserver(), and removeObserver().
|
private |
Definition at line 50 of file EnigmaMachine.hpp.
Referenced by EnigmaMachine(), and keyTransform().
|
private |
Definition at line 49 of file EnigmaMachine.hpp.
Referenced by EnigmaMachine(), EnigmaMachine(), EnigmaMachine(), keyTransform(), and setLogger().