55 std::for_each(forwardRow.begin(), forwardRow.end(), [&](
int value) {
56 if (value < 0 || value >= TRANSFORMER_SIZE) {
57 throw std::runtime_error(
"Invalid Rotor mapping: Value out of range: " + std::to_string(value));
60 throw std::runtime_error(
"Invalid Rotor mapping: Duplicate output value: " + std::to_string(value));
67 auto missing_it = std::find(seen.begin(), seen.end(),
false);
68 if (missing_it != seen.end()) {
69 throw std::runtime_error(
"Invalid Rotor mapping: Not a bijection. Missing output: " +
70 std::to_string(std::distance(seen.begin(), missing_it)));
Defines the Rotor class, a concrete implementation of the Transformer interface.
Rotor(const RotorConfig &config)
Constructor for the Rotor class. Initializes the rotor with a configuration.
void initReverseLookupTable()
Generates the reverse transformation lookup table.
AlphabetIndex transformReverse(AlphabetIndex position) const override
Transforms the given position in reverse using the reverse LUT.
void setPosition(int position) override
Sets the rotor to a specific position.
AlphabetIndex transform(AlphabetIndex position, bool reverse=false) const override
Transforms the given position based on the transformation lookup table (LUT).
int getPosition() const override
Gets the current position of the rotor.
int rotate() override
Rotates the rotor by one position. If the rotor reaches the notch position, it returns 1,...
bool isNotchPosition(int position) const
Checks if the given position is the notch position.
AlphabetIndex transformForward(AlphabetIndex position) const override
Transforms the given position forward using the forward LUT.
int initRotorPosition(int offset=0)
Initializes the rotor position. This function sets the initial position of the rotor based on the pro...
constexpr int TRANSFORMER_SIZE
Size of the alphabet/transformer (Standard Enigma is 26).
Configuration structure for an individual Rotor.
AlphabetIndex notchPosition
The position (0 - (TRANSFORMER_SIZE - 1)) at which the rotor triggers the turnover of the next rotor.
std::array< AlphabetIndex, TRANSFORMER_SIZE > wiring
The internal wiring permutation array (forward direction). Must be of size TRANSFORMER_SIZE.