-
-
Save touchopia/c8bce477ed92f4bc2677 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
| //: ROT13 Swift 1.2 - by jgallagher | |
| 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(map(s, { rot13key[$0] ?? $0 })) | |
| } | |
| let encoded = rot13("Secret Message") | |
| let decoded = rot13(encoded) | |
| print("secret message encoded \(encoded)") | |
| print("secret message decoded \(decoded)") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment