Little bit of code clean up
This commit is contained in:
parent
c96c0bd0fc
commit
d3df0d49ad
1 changed files with 1 additions and 10 deletions
|
@ -176,15 +176,6 @@ class Rotor: FixedRotor {
|
||||||
return Cryptor.alphabet[adjustedPosition]
|
return Cryptor.alphabet[adjustedPosition]
|
||||||
}
|
}
|
||||||
|
|
||||||
func convertToInverseExitCharacter(c: Character) throws -> Character {
|
|
||||||
let encodedPosition = try indexOfInAlphabet(c)
|
|
||||||
var adjustedPosition = (encodedPosition - position) % Cryptor.alphabet.count
|
|
||||||
if adjustedPosition < 0 {
|
|
||||||
adjustedPosition += Cryptor.alphabet.count
|
|
||||||
}
|
|
||||||
return Cryptor.alphabet[adjustedPosition]
|
|
||||||
}
|
|
||||||
|
|
||||||
override func encode(c: Character) throws -> Character {
|
override func encode(c: Character) throws -> Character {
|
||||||
let adjustedPosition = try getIndexAdjustedForRotation(c)
|
let adjustedPosition = try getIndexAdjustedForRotation(c)
|
||||||
let encodedChar = rotatedSeries[adjustedPosition]
|
let encodedChar = rotatedSeries[adjustedPosition]
|
||||||
|
@ -198,7 +189,7 @@ class Rotor: FixedRotor {
|
||||||
let adjustedChar = rotatedSeries[adjustedPosition]
|
let adjustedChar = rotatedSeries[adjustedPosition]
|
||||||
let lookMeUp = try indexOfInSeries(adjustedChar)
|
let lookMeUp = try indexOfInSeries(adjustedChar)
|
||||||
let decodedChar = Cryptor.alphabet[lookMeUp]
|
let decodedChar = Cryptor.alphabet[lookMeUp]
|
||||||
let finalChar = try convertToInverseExitCharacter(decodedChar)
|
let finalChar = try convertToExitCharacter(decodedChar)
|
||||||
print("Encode (pos \(position): \(c) -> \(finalChar)")
|
print("Encode (pos \(position): \(c) -> \(finalChar)")
|
||||||
return finalChar
|
return finalChar
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue