This file contains hidden or 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
| """ | |
| MIT License | |
| Copyright (c) 2022 Simon Dibbern | |
| Permission is hereby granted, free of charge, to any person obtaining a copy | |
| of this software and associated documentation files (the "Software"), to deal | |
| in the Software without restriction, including without limitation the rights | |
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
| copies of the Software, and to permit persons to whom the Software is |
This file contains hidden or 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 |