Created
February 23, 2016 14:23
-
-
Save ford-prefect/7bb6b7961c928e0264d7 to your computer and use it in GitHub Desktop.
This file contains 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
import Data.Char | |
rot13 :: String -> String | |
rot13 s = case length s of | |
0 -> "" | |
1 -> [rot13c (head s)] | |
_ -> rot13c (head s) : rot13 (tail s) | |
where | |
rot13c c | |
| isAsciiLower c = rot13b 'a' c | |
| isAsciiUpper c = rot13b 'A' c | |
| otherwise = error "Non-ASCII character" | |
rot13b b c = chr (ord b + (ord c + 13 - ord b) `mod` 26) | |
main :: IO() | |
main = print (rot13 "abcABCnopNOP") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment