Ok fair enough. Check out the updated gist, I think it more exactly fits your guidelines.
https://gist.github.com/SegFaultAX/5754209 (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!")) ) On Monday, June 10, 2013 6:16:03 PM UTC-7, Shannon Severance wrote: > > I'm new to Clojure, but with some lisp experience, I've dabbled in Scheme > for a few years. Used Racket earlier this year for a couple of sectoins of > a MOOC. And occasionally write Emacs lisp. > > The idea is to create cyptograms<https://en.wikipedia.org/wiki/Cryptogram>. > These are word puzzles using simple ciphers, and not meant for keeping real > secrets. > > ;; -> (String -> String) > ;; Returns a function that takes a string and produces a cryptogram. > ;; Multiple calls to make-crypto will return different cryptos > ;; each with different substitution keys. Multiple calls to a given > ;; crypto returned by make-crypto will use the same substitution key. > (defn make-crypto [] > (let [lower (seq "abcdefghijklmnopqrstuvwxyz") > upper (seq "ABCDEFGHIJKLMNOPQRSTUVWXYZ") > digit (seq "0123456789") > > shuffled-lower (shuffle lower) > shuffled-upper (shuffle upper) > shuffled-digit (shuffle digit) > > encrypt (reduce > conj > (map (partial assoc {}) > (concat lower upper digit) > (concat shuffled-lower shuffled-upper > shuffled-digit)))] > (fn [s] > (apply str (map #(encrypt % %) s))))) > > To me, it looks like too much code in defining the encrypt map. But I do > not know how. > > -- Shannon > -- -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.