This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Data.Char (chr, ord, toLower, isLetter) | |
-- | Vigenere Cipher | |
vigenereCipher2 :: String -> String -> String | |
vigenereCipher2 message key = zipWith (curry shiftCharByKey) message (prepareKey message key) where | |
-- | Prepares the key to skip foreign chars by setting the key to 'a' at these positions and repeats the key so it matches the messages length | |
prepareKey :: String -> String -> String | |
prepareKey [] _ = [] | |
prepareKey (m:message) (k:key) = if isLetter m then k : prepareKey message (key ++ [k]) else 'a' : prepareKey message (k : key) | |
-- | Shifts a character depending on the position of the key's character in the alphabet |