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. Com
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
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-alphan
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
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-r
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) (in
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
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 d
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 Mon
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 shuff
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
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
12 matches
Mail list logo