public void RotateToPosition(Char position) { if(!Char.IsLetter(position)) { throw new EnigmaException("Invalid rotor position: {0}".Format(position)); } var positionIndex = WireMatrix.ProjectCharacter(position); var offsetIndex = WireMatrix.ProjectCharacter(this.OffsetPosition); var delta = positionIndex - offsetIndex; if (delta < 0) { delta = 26 + delta; } for(int currentIndex = 0; currentIndex < delta; currentIndex++) { this.WiresLeft.Rotate(); this.WiresRight = this.WiresLeft.Invert(); offsetIndex = offsetIndex + 1; if (offsetIndex >= 26) { offsetIndex = 0; } this.OffsetPosition = WireMatrix.ProjectIndex(offsetIndex); } }
private void _initWires(IEnumerable<Char> wires) { this.WiresLeft = new WireMatrix(wires); this.WiresRight = this.WiresLeft.Invert(); }
public bool Rotate() { var shouldAdvance = this.OffsetPosition.Equals(this.RotateAt); if (this.RotateAtSecondary != null) { shouldAdvance = shouldAdvance || this.OffsetPosition.Equals(this.RotateAtSecondary.Value); } var offsetIndex = WireMatrix.ProjectCharacter(this.OffsetPosition); offsetIndex = offsetIndex + 1; if (offsetIndex >= 26) { offsetIndex = 0; } this.OffsetPosition = WireMatrix.ProjectIndex(offsetIndex); this.WiresLeft.Rotate(); this.WiresRight = this.WiresLeft.Invert(); return shouldAdvance; }