Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement