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

Class representing the PlugBoard (Steckerbrett) of the Enigma machine. More...

#include <PlugBoard.hpp>

Public Member Functions

 PlugBoard ()
 Constructor for the PlugBoard class. Initializes an empty plugboard with no pairs (identity mapping).
 
 PlugBoard (const std::array< PlugBoardPair, PLUGBOARD_MAX_PAIRS > &pairs)
 Constructor for the PlugBoard class. Initializes the plugboard with a given array of pairs. Validates that ports are not already used before connecting.
 
 ~PlugBoard ()=default
 
AlphabetIndex swap (AlphabetIndex key) const
 Swaps the input key based on the plugboard pairs.
 

Private Attributes

std::array< AlphabetIndex, TRANSFORMER_SIZEmapping
 

Detailed Description

Class representing the PlugBoard (Steckerbrett) of the Enigma machine.

PlugBoard Structure

The plugboard allows for manual swapping of letter pairs before they enter the rotor assembly and after they exit.

Definition at line 22 of file PlugBoard.hpp.

Constructor & Destructor Documentation

◆ PlugBoard() [1/2]

PlugBoard::PlugBoard ( )

Constructor for the PlugBoard class. Initializes an empty plugboard with no pairs (identity mapping).

Definition at line 13 of file PlugBoard.cpp.

References mapping.

◆ PlugBoard() [2/2]

PlugBoard::PlugBoard ( const std::array< PlugBoardPair, PLUGBOARD_MAX_PAIRS > &  pairs)
explicit

Constructor for the PlugBoard class. Initializes the plugboard with a given array of pairs. Validates that ports are not already used before connecting.

Parameters
pairsAn array of pairs to initialize the plugboard with.
Exceptions
std::invalid_argumentIf a port index is out of range or if there is a mapping conflict.

Validates the provided pairs before mapping them. A port is 'unused' if it maps to itself. If either port 'a' or 'b' is already mapped to something else, a conflict is reported because a socket cannot have two plugs.

Exceptions
std::invalid_argumentIf a port index is out of range or if there is a mapping conflict.

Definition at line 23 of file PlugBoard.cpp.

References mapping, and TRANSFORMER_SIZE.

◆ ~PlugBoard()

PlugBoard::~PlugBoard ( )
default

Member Function Documentation

◆ swap()

AlphabetIndex PlugBoard::swap ( AlphabetIndex  key) const

Swaps the input key based on the plugboard pairs.

Parameters
keyThe input key to be swapped.
Returns
AlphabetIndex The swapped key.

Performs a character swap using the pre-calculated mapping table.

Definition at line 55 of file PlugBoard.cpp.

References mapping, and TRANSFORMER_SIZE.

Member Data Documentation

◆ mapping

std::array<AlphabetIndex, TRANSFORMER_SIZE> PlugBoard::mapping
private

Definition at line 24 of file PlugBoard.hpp.

Referenced by PlugBoard(), PlugBoard(), and swap().


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