Created
September 19, 2014 14:59
-
-
Save jgallagher/ca55cab8126073e39bd1 to your computer and use it in GitHub Desktop.
Swift ROT13
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
| var rot13key = [Character:Character]() | |
| let uppercase = Array("ABCDEFGHIJKLMNOPQRSTUVWXYZ") | |
| let lowercase = Array("abcdefghijklmnopqrstuvwxyz") | |
| for var i = 0; i < 26; i++ { | |
| rot13key[uppercase[i]] = uppercase[(i + 13) % 26] | |
| rot13key[lowercase[i]] = lowercase[(i + 13) % 26] | |
| } | |
| func rot13(s: String) -> String { | |
| return String(seq: map(s, { rot13key[$0] ?? $0 })) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment