From 3624c712d72d246f21d4e710cec7c11e052e0326 Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Tue, 9 Dec 2025 16:32:32 +0100 Subject: Add the haskell book --- Haskell-book/11/Cipher.hs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 Haskell-book/11/Cipher.hs (limited to 'Haskell-book/11/Cipher.hs') 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 () -- cgit v1.2.3