From 799de761dcfae2fdebf13fea6584751856be9c1f Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Sun, 19 Jul 2015 01:29:55 -0700 Subject: [PATCH] Add ringPosition --- Enigma/Components.swift | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Enigma/Components.swift b/Enigma/Components.swift index 7a1f92c..e6f114d 100644 --- a/Enigma/Components.swift +++ b/Enigma/Components.swift @@ -107,7 +107,14 @@ class Rotor: FixedRotor { /** The position of first letter in `series` in the `alphabet`. */ var position: Int = 0 { willSet { - self.position = newValue % Cryptor.alphabet.count + self.position = newValue % series.count + } + } + + /** Ring position, the Ringstellung. This offsets the alphabet. */ + var ringPosition: Int = 0 { + willSet { + self.ringPosition = newValue % series.count } } @@ -117,7 +124,7 @@ class Rotor: FixedRotor { override func encode(c: Character) throws -> Character { if let offset = Rotor.alphabet.indexOf(c) { - return series[(offset + position) % series.count] + return series[(offset + ringPosition + position) % series.count] } else { throw EncoderError.InvalidCharacter(ch: c) }