-- Homework01.hs
--
-- EECS 776, Homework 1
-- Author: Stefan Mendoza
-- Date: 25 September 2015
-- Email: stefanmendoza.dev@gmail.com

module Main where

import Data.Char

rot13 :: String -> String
rot13 = map rotateChar

rotateChar :: Char -> Char
rotateChar c
    | c `elem` ['A'..'Z'] =
        if (ord c) + 13 > (ord 'Z')
            then chr $ (ord c) - 13
            else chr $ (ord c) + 13
    | c `elem` ['a'..'z'] =
        if (ord c) + 13 > (ord 'z')
            then chr $ (ord c) - 13
            else chr $ (ord c) + 13
    | otherwise = c

main :: IO ()
main = do
    putStr "Enter a phrase to be rotated: "
    s <- getLine
    putStrLn $ rot13 s
