Skip to content

Instantly share code, notes, and snippets.

@niorad
Created January 29, 2016 08:33
Show Gist options
  • Save niorad/2e55e719befcf2cd711b to your computer and use it in GitHub Desktop.
Save niorad/2e55e719befcf2cd711b to your computer and use it in GitHub Desktop.
Cesar-Cipher in Haskell
module CesarCipher where
import Data.Char
wrapMin = 97
wrapMax = 122
shifty x
| x > wrapMax = x - wrapMax + wrapMin
| otherwise = x
encrypt :: Int -> String -> String
encrypt shift message = map chr $ map shifty $ map (+shift) (map ord message)
decrypt :: Int -> String -> String
decrypt shift message = map chr $ map ((shift)-) (map ord message)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment