Advertisement
Guest User

Untitled

a guest
Dec 28th, 2014
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. import System.Environment
  2. import System.IO
  3. import Data.Char
  4.  
  5. main = do
  6. args <- getArgs
  7. let action = args !! 0
  8. shift = read (args !! 1) :: Int
  9. file = args !! 2
  10. handle <- openFile file ReadMode
  11. contents <- hGetContents handle
  12. if action == "encrypt" then
  13. putStr $ encrypt shift contents
  14. else
  15. putStr $ decrypt shift contents
  16. hClose handle
  17.  
  18. encrypt :: Int -> String -> String
  19. encrypt shift str = map (chr) $ map (+ shift) $ map (ord) str
  20.  
  21. decrypt :: Int -> String -> String
  22. decrypt shift str = encrypt (negate shift) str
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement