From b3bc058c1dfbbd82dbb3a65083bb27572ff423b3 Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Sun, 19 Jul 2015 01:30:19 -0700 Subject: [PATCH] Do rotors in the right directions, with inverted encoding as needed --- Enigma/Machine.swift | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Enigma/Machine.swift b/Enigma/Machine.swift index 9aad8b8..b3570f3 100644 --- a/Enigma/Machine.swift +++ b/Enigma/Machine.swift @@ -21,17 +21,17 @@ class Machine { } func encode(c: Character) throws -> Character { + advanceRotors() var output = c output = try plugboard.encode(output) - for rotor in rotors { - output = try rotor.encode(output) - } - output = try reflector.encode(output) for rotor in rotors.reverse() { output = try rotor.encode(output) } - output = try plugboard.encode(output) - advanceRotors() + output = try reflector.encode(output) + for rotor in rotors { + output = try rotor.inverseEncode(output) + } + output = try plugboard.inverseEncode(output) return output }