summaryrefslogtreecommitdiff
path: root/Haskell-book/13/Cipher.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Haskell-book/13/Cipher.hs')
-rw-r--r--Haskell-book/13/Cipher.hs16
1 files changed, 16 insertions, 0 deletions
diff --git a/Haskell-book/13/Cipher.hs b/Haskell-book/13/Cipher.hs
new file mode 100644
index 0000000..55dc7c4
--- /dev/null
+++ b/Haskell-book/13/Cipher.hs
@@ -0,0 +1,16 @@
+module Cipher where
+
+import Data.Char
+import Data.List
+
+vigenere :: String -> String
+vigenere = f (cycle [0, 11, 11, 24])
+ where f _ [] = []
+ f ys (' ':xs) = ' ' : (f ys xs)
+ f (y:ys) (x:xs) = (decode (x, y)) : (f ys xs)
+ where decode (x, y) = chr ((mod ((ord x) - 65 + y) 26) + 65)
+
+main :: IO ()
+main = do
+ i <- getLine
+ putStrLn $ vigenere i