Re: Making cryptograms, my first Clojure function. Feedback welcome.

2013-06-18 Thread Shannon Severance
Dan, 

Good point in general.

However, in this case, the function returned is used to make cryptograms, 
simple cryptographic word puzzles. Characters outside a-z, A-Z, 0-9 are 
passed through by design to leave punctuation and whitespace in place to 
provide structure to aid the person solving the puzzle. Stripping the 
context or shuffling them would make the problem harder. Too hard for 
intended audience.

-- Shannon Severance

On Thursday, June 13, 2013 11:49:34 AM UTC-7, Alan Thompson wrote:

 One thing that threw me at first was the double arg in the function #(encrypt 
 % %).  It took a while before I realized you were supplying each character 
 as both the map key value and a default return value (thus, a 
 non-alphanumeric char like * would come through w/o translation).  

 While this works, what I would do instead is be more explicit that only 
 certain chars are allowed in the first place.  So, I'd add a filter up 
 front that would throw an exception if any non-alphanumeric char were 
 encountered.  I can't tell you how many times this fail-fast type of 
 behavior has saved me, since it makes bugs easy to find rather than burying 
 the cause of a problem (kinda like getting an error at compile-type instead 
 of at runtime).

 Alan Thompson



-- 
-- 
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.




Re: Making cryptograms, my first Clojure function. Feedback welcome.

2013-06-18 Thread Shannon Severance
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 
1https://www.coursera.org/course/programdesignon 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.




Re: Making cryptograms, my first Clojure function. Feedback welcome.

2013-06-13 Thread Dan Neumann
I actually like the original lower/upper/digit the best:

lower (seq abcdefghijklmnopqrstuvwxyz)
upper (seq ABCDEFGHIJKLMNOPQRSTUVWXYZ)
digit (seq 0123456789)

It's just immediately obvious, especially for instance if you wanted to 
remove ambiguous chars like 0, O, l, I.


On Wednesday, June 12, 2013 7:30:31 PM UTC-5, Shannon Severance wrote:

 Thank you all, I've learned something from each entry. My latest version, 
 incorporating some of the changes suggested:

 (defn make-crypto []
   (let [lower (map char (range (int \a) (inc (int \z
 upper (map char (range (int \A) (inc (int \Z
 digit (map char (range (int \0) (inc (int \9
 
 [sl su sd] (map shuffle [lower upper digit])
 
 encrypt (zipmap (concat lower upper digit) 
 (concat sl su sd))]
 (fn [s]
   (apply str (map #(encrypt % %) s)

 I specified the range the way I did because I wanted meaningful start and 
 end points, I don't have the code points for many characters memorized.


-- 
-- 
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.




Re: Making cryptograms, my first Clojure function. Feedback welcome.

2013-06-13 Thread Alan Thompson
Looks nice, although I like Dan's explicit definition of char sequences.
 One thing that threw me at first was the double arg in the function #(encrypt
% %).  It took a while before I realized you were supplying each character
as both the map key value and a default return value (thus, a
non-alphanumeric char like * would come through w/o translation).

While this works, what I would do instead is be more explicit that only
certain chars are allowed in the first place.  So, I'd add a filter up
front that would throw an exception if any non-alphanumeric char were
encountered.  I can't tell you how many times this fail-fast type of
behavior has saved me, since it makes bugs easy to find rather than burying
the cause of a problem (kinda like getting an error at compile-type instead
of at runtime).

Alan Thompson


On Wed, Jun 12, 2013 at 5:30 PM, Shannon Severance s...@s53.me wrote:

 Thank you all, I've learned something from each entry. My latest version,
 incorporating some of the changes suggested:

 (defn make-crypto []
   (let [lower (map char (range (int \a) (inc (int \z
 upper (map char (range (int \A) (inc (int \Z
 digit (map char (range (int \0) (inc (int \9

 [sl su sd] (map shuffle [lower upper digit])

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

 I specified the range the way I did because I wanted meaningful start and
 end points, I don't have the code points for many characters memorized.

 --
 --
 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.




Re: Making cryptograms, my first Clojure function. Feedback welcome.

2013-06-12 Thread Shannon Severance
Thank you all, I've learned something from each entry. My latest version, 
incorporating some of the changes suggested:

(defn make-crypto []
  (let [lower (map char (range (int \a) (inc (int \z
upper (map char (range (int \A) (inc (int \Z
digit (map char (range (int \0) (inc (int \9

[sl su sd] (map shuffle [lower upper digit])

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

I specified the range the way I did because I wanted meaningful start and 
end points, I don't have the code points for many characters memorized.

-- 
-- 
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.




Re: Making cryptograms, my first Clojure function. Feedback welcome.

2013-06-12 Thread Kelker Ryan
No problem. I re-wrote your latest version, so let me know what you think. tdsl.core (defn make-crypto []
 (let [char-range #(map char
(range (int %1)
   (- %2 int inc)))
   [l u d] (map char-range [\a \A \0] [\z \Z \9])
   [sl su sd] (map shuffle [l u d])
   encrypt (zipmap (concat l u d) (concat sl su sd))]
   (fn [s] (apply str (map #(encrypt % %) s)
#'tdsl.core/make-crypto
tdsl.core ((make-crypto) "1 potato 2 potato")
"6 hxnvnx 0 hxnvnx"
tdsl.core ((make-crypto) "1 potato 2 potato")
"3 dszmzs 1 dszmzs"
 13.06.2013, 09:30, "Shannon Severance" s...@s53.me:Thank you all, I've learned something from each entry. My latest version, incorporating some of the changes suggested:(defn make-crypto []  (let [lower (map char (range (int \a) (inc (int \z        upper (map char (range (int \A) (inc (int \Z        digit (map char (range (int \0) (inc (int \9                [sl su sd] (map shuffle [lower upper digit])                encrypt (zipmap (concat lower upper digit)                         (concat sl su sd))]    (fn [s]      (apply str (map #(encrypt % %) s) I specified the range the way I did because I wanted meaningful start and end points, I don't have the code points for many characters memorized. --  --  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.




Re: Making cryptograms, my first Clojure function. Feedback welcome.

2013-06-11 Thread Shannon Severance
Thank you. I will sit down with the code and Clojure references to figure 
out what it is doing. 

For this problem, I don't want to use the full printable range. That would 
make the word problem too difficult. I specifically set mine up to 
substitute UPPER for UPPER, lower for lower, digit for digit, and then 
preserve any other characters, (spacing punctuation etc.) as is, to 
decrease the diffieculty.

On Monday, June 10, 2013 8:00:41 PM UTC-7, Michael-Keith Bernard wrote:

 Here is an alternative implementation that generalizes the encrypt/decrypt 
 functionality. It also uses all printable characters for the source 
 dictionary.

 https://gist.github.com/SegFaultAX/5754209

 P.S. I accidentally posted this as a reply to an older question I happened 
 to have open.

 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 cyptogramshttps://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.




Re: Making cryptograms, my first Clojure function. Feedback welcome.

2013-06-11 Thread Michael-Keith Bernard
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 cyptogramshttps://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.




Making cryptograms, my first Clojure function. Feedback welcome.

2013-06-10 Thread Shannon Severance
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.




Re: Making cryptograms, my first Clojure function. Feedback welcome.

2013-06-10 Thread Kelker Ryan
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.




Re: Making cryptograms, my first Clojure function. Feedback welcome.

2013-06-10 Thread Shannon Severance
Thank you for your example. I especially like doing sl, su, sd in one line.

However:
user= ((gen-crypto) 1 for me, 2 for you.)
1 zdu gy, 2 zdu fdx.

The numbers are coming through without translation. I believe defining 
digit as:
user= (map #(char (+ 48 %)) (range 10))
(\0 \1 \2 \3 \4 \5 \6 \7 \8 \9)
will fix that issue. Or (map char (range 48 58))

On Monday, June 10, 2013 7:42:45 PM UTC-7, Kelker Ryan wrote:

 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 javascript::
  
   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 clo...@googlegroups.comjavascript:
   Note that posts from new members are moderated - please be patient with 
 your first post.
   To unsubscribe from this group, send email to
   clojure+u...@googlegroups.com javascript:
   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+u...@googlegroups.com javascript:.
   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.




Re: Making cryptograms, my first Clojure function. Feedback welcome.

2013-06-10 Thread Kelker Ryan
 Try this version. user (defn gen-crypto []
(let [chars #(- (iterate inc %)
  (map char)
  (take 26))
  upper (chars 65)
  lower (chars 97)
  digit (take 10 (chars 48))
  [sl su sd] (map shuffle [lower upper digit])
  encrypt (apply merge
   (map hash-map
(concat lower upper digit)
(concat sl su sd)))]
  (comp #(apply str %)
(fn [x] (map #(encrypt % %) x)
#'user/gen-crypto
user ((gen-crypto) "1 for me, 2 for you.")
"8 hau yi, 3 hau raf."
user ((gen-crypto) "1 for me, 2 for you.")
"7 uga xi, 5 uga ygn."
user ((gen-crypto) "1 for me, 2 for you.")
"0 qhf oz, 8 qhf rhl." 11.06.2013, 11:58, "Shannon Severance" s...@s53.me:Thank you for your example. I especially like doing sl, su, sd in one line. However:user= ((gen-crypto) "1 for me, 2 for you.")"1 zdu gy, 2 zdu fdx." The numbers are coming through without translation. I believe defining digit as:user= (map #(char (+ 48 %)) (range 10))(\0 \1 \2 \3 \4 \5 \6 \7 \8 \9)will fix that issue. Or (map char (range 48 58))On Monday, June 10, 2013 7:42:45 PM UTC-7, Kelker Ryan wrote: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 clo...@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+u...@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+u...@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.




Re: Making cryptograms, my first Clojure function. Feedback welcome.

2013-06-10 Thread Michael-Keith Bernard
Here is an alternative implementation that generalizes the encrypt/decrypt 
functionality. It also uses all printable characters for the source 
dictionary.

https://gist.github.com/SegFaultAX/5754209

P.S. I accidentally posted this as a reply to an older question I happened 
to have open.

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 cyptogramshttps://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.