use crate::state::EnigmaState;
pub trait SteppingStrategy {
fn step(&self, state: &mut EnigmaState) -> Result<(), String>;
}
pub struct LinearStepping {
pub modulus: u32,
}
impl LinearStepping {
pub fn new(modulus: u32) -> Self {
Self { modulus }
}
}
impl SteppingStrategy for LinearStepping {
fn step(&self, state: &mut EnigmaState) -> Result<(), String> {
if self.modulus == 0 {
return Err("modulus must be greater than zero".into());
}
if state.rotor_positions.is_empty() {
return Err("no rotors defined in state".into());
}
state.step_counter += 1;
for pos in &mut state.rotor_positions {
*pos += 1;
if *pos < self.modulus {
break;
}
*pos = 0;
}
Ok(())
}
}