Last active
July 19, 2017 19:33
-
-
Save KentaKudo/edb639fe5faa4d86167ce35c27df4a21 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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