Here's my re-write.
user> (defn gen-crypto [] (let [atoz (range 65 91) upper (map char atoz) lower (map #(char (+ % 32)) atoz) digit (range 10) [sl su sd] (map shuffle [lower upper digit]) encrypt (reduce conj (map hash-map (concat lower upper digit) (concat sl su sd)))] (fn [s] (apply str (map #(encrypt % %) s))))) #'user/gen-crypto user> ((gen-crypto) "abc") "ghm" user> ((gen-crypto) "abc") "efz"
11.06.2013, 10:31, "Shannon Severance" <s...@s53.me>:
> 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. 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.
--
--
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.