Skip to content

Instantly share code, notes, and snippets.

@Denommus
Last active September 16, 2015 20:51
Show Gist options
  • Save Denommus/80aa4f00a89b82987fa1 to your computer and use it in GitHub Desktop.
Save Denommus/80aa4f00a89b82987fa1 to your computer and use it in GitHub Desktop.
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