Caesar cipher: Difference between revisions
Content added Content deleted
Cyril Nocton (talk | contribs) m (→Main solution) |
Cyril Nocton (talk | contribs) |
||
Line 1,891: | Line 1,891: | ||
"The quick brown fox jumps over the lazy dog"</pre> |
"The quick brown fox jumps over the lazy dog"</pre> |
||
==== |
====Alternate version==== |
||
1. Note |
1. Note |
||
<pre>if |
<pre>if caesar(txt offset) = cyphertext then caesar(cyphertext -offset) = txt</pre> |
||
See « caesar-decipher » function above. |
|||
2. Program |
2. Program |
||
<lang lisp>(defconstant + |
<lang lisp>(defconstant +a+ "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz") |
||
(defun |
(defun caesar (txt offset) |
||
(map 'string |
(map 'string |
||
#'(lambda (x) |
#'(lambda (x) |
||
(if (find x + |
(if (find x +a+) |
||
(char + |
(char +a+ (mod (+ (position x +a+) (* 2 offset)) 52)) |
||
x)) |
x)) |
||
txt))</lang> |
|||
3. Execution |
3. Execution |
||
See 1. |
|||
{{out}} |
{{out}} |
||
<pre>( |
<pre>(caesar "Ave Caesar morituri te salutant" 13) |
||
Nir Pnrfne zbevghev gr fnyhgnag |
Nir Pnrfne zbevghev gr fnyhgnag |
||
( |
(caesar "Nir Pnrfne zbevghev gr fnyhgnag" -13) |
||
Ave Caesar morituri te salutant</pre> |
Ave Caesar morituri te salutant</pre> |
||