Last active
August 29, 2015 14:19
-
-
Save pstephens/4edc5f68fd24173f5d5c to your computer and use it in GitHub Desktop.
Alphabet Cipher solution
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
;; Solution to https://github.com/gigasquid/wonderland-clojure-katas/tree/master/alphabet-cipher | |
(ns alphabet-cipher.coder) | |
(defn crypt [op keyword message] | |
(letfn [ | |
(tochar [idx] (char (+ idx (int \a)))) | |
(toidx [ch] (- (int ch) (int \a))) | |
(encode [keychar msgchar] (tochar (mod (op (toidx msgchar) (toidx keychar)) 26)))] | |
(->> message | |
(map encode (cycle keyword)) | |
(apply str)))) | |
(defn encode [keyword message] (crypt + keyword message)) | |
(defn decode [keyword message] (crypt - keyword message)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment