Created
February 2, 2012 00:46
-
-
Save ecounysis/1720476 to your computer and use it in GitHub Desktop.
Caesar Cypher in Haskell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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