Skip to content

Instantly share code, notes, and snippets.

@KentaKudo
Last active July 19, 2017 19:33
Show Gist options
  • Select an option

  • Save KentaKudo/edb639fe5faa4d86167ce35c27df4a21 to your computer and use it in GitHub Desktop.

Select an option

Save KentaKudo/edb639fe5faa4d86167ce35c27df4a21 to your computer and use it in GitHub Desktop.
public struct RotorBox {
public struct Rotor {
let forward: Cipher
let backward: Cipher
var position: Token
init(_ forward: @escaping Cipher, position: Token) {
self.forward = forward
// backwardはforwardのときと逆に動作する (FIXME)
self.backward = { token in
let tokens: [Token] = [.A, .B, .C, .D, .E, .F, .G, .H, .I, .J, .K, .L, .M, .N, .O, .P, .Q, .R, .S, .T, .U, .V, .W, .X, .Y, .Z]
return tokens.filter{ forward($0) == token }.first!
}
self.position = position
}
mutating func rotate() {
position = position.next()
}
}
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment