import Data.Char
import Text.Printf


crypt f key = map toLetter . zipWith f (cycle key)
  where toLetter = chr . (+) (ord 'A')


enc k c = (ord k + ord c) `mod` 26
dec k c = (ord c - ord k) `mod` 26


encrypt = crypt enc
decrypt = crypt dec


convert = map toUpper . filter isLetter

main :: IO ()
main = do
  let key  = "VIGENERECIPHER"
      text = "Beware the Jabberwock, my son! The jaws that bite, "
             ++ "the claws that catch!"
      encr = encrypt key $ convert text
      decr = decrypt key encr
  printf "    Input:%s\n      Key:%s\nEncrypted:%s\nDecrypted:%s\n"
    text key encr decr