Last active
September 16, 2015 20:51
-
-
Save Denommus/80aa4f00a89b82987fa1 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
import Data.Char (chr, ord) | |
import System.Environment (getArgs) | |
cycleRange :: Char -> Int -> Char -> Char | |
cycleRange start n c | a <= x && x < a+26 = chr $ ((x - a + n) `mod` 26) + a | |
| otherwise = c | |
where x = ord c | |
a = ord start | |
caesarCypher :: Int -> String -> String | |
caesarCypher n = map caesarChar | |
where caesarChar = cycleRange 'a' n . cycleRange 'A' n | |
main :: IO () | |
main = do | |
[file] <- getArgs | |
putStrLn =<< caesarCypher 21 <$> readFile file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment