Created
December 28, 2014 15:48
-
-
Save siddMahen/db6ae04949d519f2beeb 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 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