summaryrefslogtreecommitdiff
path: root/Haskell-book/13/Cipher.hs
blob: 55dc7c4cbaa38a350a870661b1f0d8b86c348ee8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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