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/11/Cipher.hs | |
| parent | c95abc31d62e296db4f1b537e3de440dd40defd1 (diff) | |
| download | book-exercises-3624c712d72d246f21d4e710cec7c11e052e0326.tar.gz | |
Add the haskell book
Diffstat (limited to 'Haskell-book/11/Cipher.hs')
| -rw-r--r-- | Haskell-book/11/Cipher.hs | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/Haskell-book/11/Cipher.hs b/Haskell-book/11/Cipher.hs new file mode 100644 index 0000000..92e0e7d --- /dev/null +++ b/Haskell-book/11/Cipher.hs @@ -0,0 +1,24 @@ +module Cipher where + +import Data.Char +import Data.List + +decode :: (Char, Int) -> Char +decode (x, y) = chr ((mod ((ord x) - 65 + y) 26) + 65) + +decodeWithKey :: [Int] -> String -> String +decodeWithKey _ [] = [] +decodeWithKey ys (' ':xs) = ' ' : (decodeWithKey ys xs) +decodeWithKey (y:ys) (x:xs) = (decode (x, y)) : (decodeWithKey ys xs) + +vigenere :: String -> String +vigenere = decodeWithKey (cycle [0, 11, 11, 24]) + +caeser :: String -> String +caeser = decodeWithKey (cycle [11]) + +main :: IO () +main = do + putStrLn (vigenere "MEET AT DAWN") + putStrLn (caeser "MEET AT DAWN") + return () |
