Do rotors in the right directions, with inverted encoding as needed
This commit is contained in:
parent
799de761dc
commit
b3bc058c1d
1 changed files with 6 additions and 6 deletions
|
@ -21,17 +21,17 @@ class Machine {
|
||||||
}
|
}
|
||||||
|
|
||||||
func encode(c: Character) throws -> Character {
|
func encode(c: Character) throws -> Character {
|
||||||
|
advanceRotors()
|
||||||
var output = c
|
var output = c
|
||||||
output = try plugboard.encode(output)
|
output = try plugboard.encode(output)
|
||||||
for rotor in rotors {
|
|
||||||
output = try rotor.encode(output)
|
|
||||||
}
|
|
||||||
output = try reflector.encode(output)
|
|
||||||
for rotor in rotors.reverse() {
|
for rotor in rotors.reverse() {
|
||||||
output = try rotor.encode(output)
|
output = try rotor.encode(output)
|
||||||
}
|
}
|
||||||
output = try plugboard.encode(output)
|
output = try reflector.encode(output)
|
||||||
advanceRotors()
|
for rotor in rotors {
|
||||||
|
output = try rotor.inverseEncode(output)
|
||||||
|
}
|
||||||
|
output = try plugboard.inverseEncode(output)
|
||||||
return output
|
return output
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue