Skip to content

Instantly share code, notes, and snippets.

@amalloy
Created August 20, 2012 09:08
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 amalloy/3402511 to your computer and use it in GitHub Desktop.
Save amalloy/3402511 to your computer and use it in GitHub Desktop.
(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