Skip to content

Instantly share code, notes, and snippets.

@siddMahen
Created December 28, 2014 15:48
Show Gist options
  • Save siddMahen/db6ae04949d519f2beeb to your computer and use it in GitHub Desktop.
Save siddMahen/db6ae04949d519f2beeb to your computer and use it in GitHub Desktop.
import System.Environment
import System.IO
import Data.Char
main = do
args <- getArgs
let action = args !! 0
shift = read (args !! 1) :: Int
file = args !! 2
handle <- openFile file ReadMode
contents <- hGetContents handle
if action == "encrypt" then
putStr $ encrypt shift contents
else
putStr $ decrypt shift contents
hClose handle
encrypt :: Int -> String -> String
encrypt shift str = map (chr) $ map (+ shift) $ map (ord) str
decrypt :: Int -> String -> String
decrypt shift str = encrypt (negate shift) str
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment