Skip to content

Instantly share code, notes, and snippets.

@SegFaultAX
Last active December 18, 2015 08:29
Show Gist options
  • Save SegFaultAX/5754209 to your computer and use it in GitHub Desktop.
Save SegFaultAX/5754209 to your computer and use it in GitHub Desktop.
Full alphabet cryptograms
(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