25 lines
611 B
Haskell
25 lines
611 B
Haskell
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 ()
|