Skip to content

Instantly share code, notes, and snippets.

@shepting
Forked from jeremy-w/rot13.swift
Last active August 29, 2015 14:08
Show Gist options
  • Save shepting/d094348a5042e36e3e42 to your computer and use it in GitHub Desktop.
Save shepting/d094348a5042e36e3e42 to your computer and use it in GitHub Desktop.
// Playground - noun: a place where people can play
import UIKit
let lettersArray = Array("ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz")
func rot13(input: String) -> String {
return reduce(input, "", { result, letter in
if let i = find(lettersArray, letter) {
return result + String(lettersArray[i + 13])
} else {
return result + String(letter)
}
})
}
rot13("rot13")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment