caesar cipher


See On Github

Data

Contributor

Generic placeholder thumbnail

by warreee

in haskell

Tags

Source Code

module CaesarCipher where

import Data.Char

encode :: Int -> String -> String
encode shift = map (\s -> chr $ ord s + shift) 

decode :: Int -> String -> String
decode shift = encode $ negate shift
module CaesarCipher_Test ( main ) where
import CaesarCipher

main = do
    putStrLn "The message \"Haskell is awesome\" encoded with a shift of 5 characters: "
    putStrLn $ encode 5 "Haskell is awesome"
    putStrLn "The message \"Mfxpjqq%nx%f|jxtrj\" decoded with a shift of 5 characters: "
    putStrLn $ decode 5 "Mfxpjqq%nx%f|jxtrj"