Skip to content

Instantly share code, notes, and snippets.

@ecounysis
Created February 2, 2012 00:46
Show Gist options
  • Save ecounysis/1720476 to your computer and use it in GitHub Desktop.
Save ecounysis/1720476 to your computer and use it in GitHub Desktop.
Caesar Cypher in Haskell
import Char
cCipher s = encode 3 s
cDecipher s = decode 3 s
encode sh s = map (encodeChar sh) s
decode sh s = encode (-sh) s
encodeChar sh c
| isChar c = shift sh c
| otherwise = c
shift sh c = toChar (((toInt c) + sh) `mod` 74)
isChar c = (ord c >= ord '0' && ord c <= ord 'z')
toInt c = ord c - ord '0'
toChar i = chr (i + ord '0')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment