EnigmaMachineCore 0.1.0
A modular Enigma Machine simulation in C++20
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Private Attributes | List of all members
EnigmaMachine Class Reference

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
 
EnigmaMachineoperator= (const EnigmaMachine &)=delete
 
 EnigmaMachine (EnigmaMachine &&other) noexcept
 
EnigmaMachineoperator= (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< RotorBoxrotorBox
 
std::unique_ptr< PlugBoardplugBoard
 
std::vector< IEnigmaObserver * > observers
 
ILogger * logger = nullptr
 

Detailed Description

Class representing the Enigma machine.

Complete Signal Flow

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.

Constructor & Destructor Documentation

◆ EnigmaMachine() [1/7]

EnigmaMachine::EnigmaMachine ( const EnigmaMachineConfig config,
ILogger *  logger = nullptr 
)
explicitprotected

Internal constructor using the configuration struct. Accessible to tests and benchmarks, but hidden from the public API.

Parameters
configThe machine configuration.
loggerOptional logger for event reporting.

Definition at line 74 of file EnigmaMachine.cpp.

References rotorBox.

◆ EnigmaMachine() [2/7]

EnigmaMachine::EnigmaMachine ( EnigmaMachineConfig &&  config,
ILogger *  logger = nullptr 
)
explicitprotected

Internal constructor using the configuration struct (move version).

Parameters
configThe machine configuration.
loggerOptional logger for event reporting.

Definition at line 81 of file EnigmaMachine.cpp.

References rotorBox.

◆ EnigmaMachine() [3/7]

EnigmaMachine::EnigmaMachine ( ILogger *  logger = nullptr)
explicit

Default Constructor. Initializes a standard Enigma Machine (3 Rotors, standard Reflector).

Parameters
loggerOptional 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() [4/7]

EnigmaMachine::EnigmaMachine ( const IAssetProvider provider,
std::string_view  fileName,
std::string_view  assetPath = "",
ILogger *  logger = nullptr 
)

File-based Constructor using a specific Asset Provider.

Parameters
providerThe asset provider to use for loading configuration.
fileNameThe path to the TOML configuration file.
assetPathOptional base directory for assets.
loggerOptional logger for event reporting.

Definition at line 70 of file EnigmaMachine.cpp.

◆ EnigmaMachine() [5/7]

EnigmaMachine::EnigmaMachine ( std::string_view  fileName,
std::string_view  assetPath = "",
ILogger *  logger = nullptr 
)
explicit

File-based Constructor. Initializes the machine by parsing a TOML configuration file from the filesystem.

Parameters
fileNameThe path to the TOML configuration file.
assetPathOptional base directory for assets.
loggerOptional logger for event reporting.

Definition at line 89 of file EnigmaMachine.cpp.

◆ ~EnigmaMachine()

EnigmaMachine::~EnigmaMachine ( )
overridedefault

◆ EnigmaMachine() [6/7]

EnigmaMachine::EnigmaMachine ( const EnigmaMachine )
delete

◆ EnigmaMachine() [7/7]

EnigmaMachine::EnigmaMachine ( EnigmaMachine &&  other)
noexcept

Definition at line 94 of file EnigmaMachine.cpp.

References removeObserver().

+ Here is the call graph for this function:

Member Function Documentation

◆ keyTransform()

AlphabetIndex EnigmaMachine::keyTransform ( AlphabetIndex  input)

Transforms the input key through the rotor box.

Parameters
inputThe input key to be transformed.
Returns
AlphabetIndex The transformed output key.

The transformation follows the historic Enigma signal path:

  1. Pass through Plugboard (Forward).
  2. Pass through RotorBox (Rotors -> Reflector -> Rotors).
  3. Pass through Plugboard (Reverse).

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:

◆ onCharEncrypted()

void EnigmaMachine::onCharEncrypted ( char  input,
char  output 
)
overridevirtual

Called when a character is encrypted/decrypted.

Parameters
inputThe original input character.
outputThe 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:

◆ onRotorStepped()

void EnigmaMachine::onRotorStepped ( int  rotorIndex,
AlphabetIndex  position 
)
overridevirtual

Called when a rotor steps.

Parameters
rotorIndexThe index of the rotor (0 is the rightmost/fastest).
positionThe new position of the rotor (0-25).

Implements IEnigmaObserver.

Definition at line 160 of file EnigmaMachine.cpp.

References observers.

◆ operator=() [1/2]

EnigmaMachine & EnigmaMachine::operator= ( const EnigmaMachine )
delete

◆ operator=() [2/2]

EnigmaMachine & EnigmaMachine::operator= ( EnigmaMachine &&  other)
noexcept

Definition at line 105 of file EnigmaMachine.cpp.

◆ processBuffer()

void EnigmaMachine::processBuffer ( std::span< AlphabetIndex >  buffer)

Processes a buffer of alphabet indexes in-place.

Parameters
bufferThe span of characters to transform.

Definition at line 140 of file EnigmaMachine.cpp.

References keyTransform().

+ Here is the call graph for this function:

◆ registerObserver()

void EnigmaMachine::registerObserver ( IEnigmaObserver observer)

Registers an observer to receive notifications.

Parameters
observerThe observer to register.

Definition at line 151 of file EnigmaMachine.cpp.

References observers.

Referenced by runApplication().

+ Here is the caller graph for this function:

◆ removeObserver()

void EnigmaMachine::removeObserver ( IEnigmaObserver observer)

Removes an observer.

Parameters
observerThe observer to remove.

Definition at line 153 of file EnigmaMachine.cpp.

References observers.

Referenced by EnigmaMachine().

+ Here is the caller graph for this function:

◆ setLogger()

void EnigmaMachine::setLogger ( ILogger *  logger)

Sets the logger for the machine.

Parameters
loggerThe logger to use.

Definition at line 144 of file EnigmaMachine.cpp.

References logger, and rotorBox.

Member Data Documentation

◆ logger

ILogger* EnigmaMachine::logger = nullptr
private

Definition at line 52 of file EnigmaMachine.hpp.

Referenced by EnigmaMachine(), and setLogger().

◆ observers

std::vector<IEnigmaObserver*> EnigmaMachine::observers
private

◆ plugBoard

std::unique_ptr<PlugBoard> EnigmaMachine::plugBoard
private

Definition at line 50 of file EnigmaMachine.hpp.

Referenced by EnigmaMachine(), and keyTransform().

◆ rotorBox

std::unique_ptr<RotorBox> EnigmaMachine::rotorBox
private

The documentation for this class was generated from the following files: