Last active
December 18, 2015 08:29
-
-
Save SegFaultAX/5754209 to your computer and use it in GitHub Desktop.
Full alphabet cryptograms
This file contains hidden or 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
(defn crypt-range [low high] | |
(let [chars (map char (range low high))] | |
(zipmap chars (shuffle chars)))) | |
(defn make-crypto [] | |
(let [ranges [[97 123] [65 91] [48 58]]] | |
(apply merge (map #(apply crypt-range %) ranges)))) | |
(defn encrypt [crypto s] | |
"Encrypt string with crypto map" | |
(apply str (map #(crypto % %) s))) | |
(defn decrypt [crypto s] | |
"Decrypt string with crypto map" | |
(let [decrypto (clojure.set/map-invert crypto)] | |
(apply str (map #(decrypto % %) s)))) | |
(comment | |
(def crypt (make-crypto)) | |
(encrypt crypt "hello GOODBYE 12345") | |
(decrypt crypt (encrypt crypt "still reversible!")) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment