Created
September 28, 2016 16:12
-
-
Save codinguncut/65c17c8c965592f25807d340fd7beae9 to your computer and use it in GitHub Desktop.
alphabet kata
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 | |
char_to_pos c = ord c - ord 'a' | |
pos_to_char p = chr (p `mod` 26 + ord('a')) | |
transcode_letter op key text = pos_to_char (text_offset `op` key_offset + 26) | |
where [key_offset, text_offset] = map char_to_pos [key, text] | |
encode_letter = transcode_letter (+) | |
decode_letter = transcode_letter (-) | |
transcode_string f key = map (uncurry f) . zip (cycle key) | |
encode_string = transcode_string encode_letter | |
decode_string = transcode_string decode_letter |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment