Add ringPosition
This commit is contained in:
parent
a01af97ffc
commit
799de761dc
1 changed files with 9 additions and 2 deletions
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue