My wife informed me that cryptograms typically use the same substitutions 
for upper and lower case letters. If a becomes h, then A becomes H.

Changes:

   1. Revert to explicit strings for characters to shuffle, without using 
   range and what not.
   2. a-z mapping matches A-Z mapping
   3. Comments to clarify this is for a word puzzle. Additional based on 
   the How to Design Functions from Gregor Kiczales Introduction to 
   Systematic Program Design - Part 
1<https://www.coursera.org/course/programdesign>on coursera. (Pr

;;   -> (String -> String)
;; Returns an anonymous function (AF) closed over a simple
;; replacement cipher.
;; 
;; AF has type String -> String
;; Produce a simple cryptogram, a word game, based on the 
;; cipher in its closure.
;;
;; ** THIS IS FOR WORD GAMES/ENTERTAINMENT ONLY **
;; ** DO NOT USE TO ENCRYPT ANYTHING YOU WISH   **
;; ** TO KEEP SECRET.                           **
;;
;; The replacement cipher has the following properties
;; Each digit is replaced with a digit.
;; Each letter is replaced with a letter.
;; Case is preserved.
;; The mapping between a letter and another
;;    is the same irrespective of case.
;;
;; 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 [make-upper #(.toUpperCase (apply str %))

        lower (seq "abcdefghijklmnopqrstuvwxyz")
        digit (seq "0123456789")
        
        [sl sd] (map shuffle [lower digit])

        encrypt (zipmap (concat lower (make-upper lower)  digit) 
                        (concat sl    (make-upper sl)     sd))]
    (fn [s]
      (apply str (map #(encrypt % %) s)))))


Examples using famous phrases in US history:


user=> ((make-crypto) "Only Thing We Have to Fear Is Fear Itself.")
"Fxkv Wjyxb Di Jnoi wf Rinp Yg Rinp Ywgikr."

user=> ((make-crypto) "I have a dream that my four little children will one 
#_=> day live in a nation where they will not be judged by the color of 
#_=> their skin but by the content of their character.")
"B axgv x fevxl caxc lm hzie ybccyv rabyfevn qbyy znv\n
fxm ybgv bn x nxcbzn qavev cavm qbyy nzc ov difkvf om cav rzyze zh\
ncavbe jpbn oicom cav rzncvnc zh cavbe raxexrcve."

user=> ((make-crypto) "One small step for man, one giant leap for mankind.")
"Bqy psxkk pzyc hbv sxq, bqy grxqz kyxc hbv sxqnrqi."
 
-- 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.


Reply via email to