diff options
| author | Eugen Wissner <belka@caraus.de> | 2025-12-09 16:32:32 +0100 |
|---|---|---|
| committer | Eugen Wissner <belka@caraus.de> | 2025-12-09 16:32:32 +0100 |
| commit | 3624c712d72d246f21d4e710cec7c11e052e0326 (patch) | |
| tree | f385cb51c72a0c5eeb2057609b75f5f8c6c4f272 /Haskell-book/09/src/Cipher.purs | |
| parent | c95abc31d62e296db4f1b537e3de440dd40defd1 (diff) | |
| download | book-exercises-3624c712d72d246f21d4e710cec7c11e052e0326.tar.gz | |
Add the haskell book
Diffstat (limited to 'Haskell-book/09/src/Cipher.purs')
| -rw-r--r-- | Haskell-book/09/src/Cipher.purs | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/Haskell-book/09/src/Cipher.purs b/Haskell-book/09/src/Cipher.purs new file mode 100644 index 0000000..d5605c2 --- /dev/null +++ b/Haskell-book/09/src/Cipher.purs @@ -0,0 +1,15 @@ +module Cipher where + +import Data.Char (fromCharCode, toCharCode) +import Data.String (fromCharArray, toCharArray) +import Prelude + +caesar :: Int -> String -> String +caesar key s = fromCharArray $ map shiftRight (toCharArray s) + where shiftRight char = fromCharCode $ mod (ord char) 26 + ord = (add key) <<< toCharCode + +unCaesar :: Int -> String -> String +unCaesar key s = fromCharArray $ map shiftLeft (toCharArray s) + where shiftLeft char = fromCharCode $ ord char + ord chr = ((toCharCode chr) - (mod key 26)) + 26 |
