Created
August 20, 2012 09:08
-
-
Save amalloy/3402511 to your computer and use it in GitHub Desktop.
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
(def charset "ABCDEFGHIJKLMNOPQRSTUVWXYZ") | |
(def N (count charset)) | |
(defn valueFor [x] | |
(.indexOf charset (str x))) | |
(defn charFor [x] | |
(nth charset x)) | |
(defn combiner [o] | |
(fn [& chars] | |
(charFor (mod (reduce o (map valueFor chars)) N)))) | |
(defn crypto [f] | |
(fn [data key] | |
(apply str | |
(map (combiner f) data (cycle key))))) | |
(def encrypt (crypto +)) | |
(def decrypt (crypto -)) | |
(println (encrypt "THECAKEISALIE" "GLADOS")) | |
(println (decrypt "ZSEFOCKTSDZAK" "GLADOS")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment