Skip to content

Instantly share code, notes, and snippets.

@codinguncut
Created September 28, 2016 16:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codinguncut/65c17c8c965592f25807d340fd7beae9 to your computer and use it in GitHub Desktop.
Save codinguncut/65c17c8c965592f25807d340fd7beae9 to your computer and use it in GitHub Desktop.
alphabet kata
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