Skip to content

Instantly share code, notes, and snippets.

@jgallagher
Created September 19, 2014 14:59
Show Gist options
  • Select an option

  • Save jgallagher/ca55cab8126073e39bd1 to your computer and use it in GitHub Desktop.

Select an option

Save jgallagher/ca55cab8126073e39bd1 to your computer and use it in GitHub Desktop.
Swift ROT13
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