|
EnigmaMachineCore 0.1.0
A modular Enigma Machine simulation in C++20
|
Class representing a rotor in the Enigma machine. This class inherits from the Transformer class and implements the functionality for transforming positions based on the rotor's transformation lookup table (LUT). It also handles the rotor's rotation and notch position. More...
#include <Rotor.hpp>
Inheritance diagram for Rotor:
Collaboration diagram for Rotor:Public Member Functions | |
| Rotor (const RotorConfig &config) | |
| Constructor for the Rotor class. Initializes the rotor with a configuration. | |
| Rotor (RotorConfig &&config) | |
| ~Rotor () override=default | |
| AlphabetIndex | transform (AlphabetIndex position, bool reverse=false) const override |
| Transforms the given position based on the transformation lookup table (LUT). | |
| AlphabetIndex | transformForward (AlphabetIndex position) const override |
| Transforms the given position forward using the forward LUT. | |
| AlphabetIndex | transformReverse (AlphabetIndex position) const override |
| Transforms the given position in reverse using the reverse LUT. | |
| int | rotate () override |
| Rotates the rotor by one position. If the rotor reaches the notch position, it returns 1, indicating that the next rotor should rotate. Otherwise, it returns 0. | |
| void | setPosition (int position) override |
| Sets the rotor to a specific position. | |
| int | getPosition () const override |
| Gets the current position of the rotor. | |
| bool | isNotchPosition (int position) const |
| Checks if the given position is the notch position. | |
Public Member Functions inherited from Transformer | |
| Transformer () | |
| Constructor for the Transformer class. Initializes the transformer type to NotDefined. | |
| virtual | ~Transformer ()=default |
| int | sizeOfLookupTable () const |
| Calculates the size of the transformation lookup table (LUT). | |
| TransformerType | getType () const |
| Returns the type of the transformer. | |
Private Member Functions | |
| void | initReverseLookupTable () |
| Generates the reverse transformation lookup table. | |
| int | initRotorPosition (int offset=0) |
| Initializes the rotor position. This function sets the initial position of the rotor based on the provided offset. | |
Private Attributes | |
| int | notchPosition |
| int | rotationCount |
Additional Inherited Members | |
Protected Member Functions inherited from Transformer | |
| void | setTransformValue (int row, int col, AlphabetIndex value) |
| Sets a value in the transformation lookup table. | |
| AlphabetIndex | getTransformValue (int row, int col) const |
| Gets a value from the transformation lookup table. | |
| void | fillTransformRow (int row, AlphabetIndex value) |
| Fills a row of the transformation lookup table with a specific value. | |
| void | copyTransformRow (int row, const std::array< AlphabetIndex, TRANSFORMER_SIZE > &values) |
| Copies a whole array into a row of the transformation lookup table. | |
| const std::array< AlphabetIndex, TRANSFORMER_SIZE > & | getTransformRow (int row) const |
| Gets a read-only reference to a row in the transformation lookup table. Useful for using standard algorithms like std::find. | |
Protected Attributes inherited from Transformer | |
| TransformerType | type |
Class representing a rotor in the Enigma machine. This class inherits from the Transformer class and implements the functionality for transforming positions based on the rotor's transformation lookup table (LUT). It also handles the rotor's rotation and notch position.
|
explicit |
Constructor for the Rotor class. Initializes the rotor with a configuration.
| config | The RotorConfig structure containing wiring and notch info. |
Initializes the Rotor by:
initReverseLookupTable.| std::runtime_error | If the wiring size in the config is incorrect. |
Definition at line 22 of file Rotor.cpp.
References Transformer::copyTransformRow(), initReverseLookupTable(), initRotorPosition(), RotorConfig::notchPosition, notchPosition, rotationCount, Rotor, Transformer::type, and RotorConfig::wiring.
Here is the call graph for this function:
|
explicit |
Definition at line 33 of file Rotor.cpp.
References Transformer::copyTransformRow(), initReverseLookupTable(), initRotorPosition(), notchPosition, rotationCount, Rotor, and Transformer::type.
Here is the call graph for this function:
|
overridedefault |
|
overridevirtual |
Gets the current position of the rotor.
Reimplemented from Transformer.
Definition at line 157 of file Rotor.cpp.
References rotationCount.
|
private |
Generates the reverse transformation lookup table.
| std::runtime_error | If reverse mapping generation fails. |
Generates the mathematical inverse of the forward wiring to handle the return signal.
Definition at line 50 of file Rotor.cpp.
References Transformer::getTransformRow(), Transformer::setTransformValue(), and TRANSFORMER_SIZE.
Referenced by Rotor(), and Rotor().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Initializes the rotor position. This function sets the initial position of the rotor based on the provided offset.
| offset | The initial offset for the rotor position. |
Sets the internal rotation counter to the specified offset.
Definition at line 77 of file Rotor.cpp.
References rotationCount.
Referenced by Rotor(), and Rotor().
Here is the caller graph for this function:| bool Rotor::isNotchPosition | ( | int | position | ) | const |
Checks if the given position is the notch position.
| position | The position to check. |
Definition at line 82 of file Rotor.cpp.
References notchPosition.
Referenced by rotate().
Here is the caller graph for this function:
|
overridevirtual |
Rotates the rotor by one position. If the rotor reaches the notch position, it returns 1, indicating that the next rotor should rotate. Otherwise, it returns 0.
Increments the rotor's position by one step (modulo TRANSFORMER_SIZE). Checks if the new position corresponds to the notch position.
Implements Transformer.
Definition at line 143 of file Rotor.cpp.
References isNotchPosition(), rotationCount, and TRANSFORMER_SIZE.
Here is the call graph for this function:
|
overridevirtual |
Sets the rotor to a specific position.
| position | The position to set the rotor to (0 to TRANSFORMER_SIZE - 1). |
Manually sets the current rotational position of the rotor. This is used for setting up the initial machine state key.
Reimplemented from Transformer.
Definition at line 155 of file Rotor.cpp.
References rotationCount.
|
overridevirtual |
Transforms the given position based on the transformation lookup table (LUT).
| position | The current position in the rotor. |
| reverse | If true, transforms using the reverse LUT; otherwise, uses the forward LUT. |
This method is const-qualified, ensuring that the signal transformation does not modify the internal state of the rotor.
Handles the relative coordinate shift caused by the rotor's rotation.
Implements Transformer.
Definition at line 93 of file Rotor.cpp.
References transformForward(), and transformReverse().
Here is the call graph for this function:
|
overridevirtual |
Transforms the given position forward using the forward LUT.
| position | The current position in the rotor (0 to TRANSFORMER_SIZE - 1). |
Implements the forward signal path through the rotor's specific wiring, accounting for current rotation offset.
Performs the forward signal pass (right-to-left).
Implements Transformer.
Definition at line 103 of file Rotor.cpp.
References Transformer::getTransformValue(), rotationCount, and TRANSFORMER_SIZE.
Referenced by transform().
Here is the call graph for this function:
Here is the caller graph for this function:
|
overridevirtual |
Transforms the given position in reverse using the reverse LUT.
| position | The current position in the rotor (0 to TRANSFORMER_SIZE - 1). |
Implements the return signal path through the rotor's specific wiring, accounting for current rotation offset.
Performs the reverse signal pass (left-to-right).
Implements Transformer.
Definition at line 123 of file Rotor.cpp.
References Transformer::getTransformValue(), rotationCount, and TRANSFORMER_SIZE.
Referenced by transform().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Definition at line 19 of file Rotor.hpp.
Referenced by Rotor(), Rotor(), and isNotchPosition().
|
private |
Definition at line 20 of file Rotor.hpp.
Referenced by Rotor(), Rotor(), getPosition(), initRotorPosition(), rotate(), setPosition(), transformForward(), and transformReverse().