Caesar cipher: Difference between revisions

Content deleted Content added
Line 1,891:
"The quick brown fox jumps over the lazy dog"</pre>
 
====VariantAlternate version====
1. Note
<pre>if rotcaesar(texttxt shiftoffset) = cyphertext then rotcaesar(cyphertext -shiftoffset) = texttxt</pre>
 
See « caesar-decipher » function above.
 
2. Program
 
<lang lisp>(defconstant +rota+ "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz")
(defun rotcaesar (texttxt shiftoffset)
(map 'string
#'(lambda (x)
(if (find x +rota+)
(char +rota+ (mod (+ (position x +rota+) (* 2 shiftoffset)) 52))
x))
texttxt))</lang>
 
3. Execution
 
See 1.
 
{{out}}
<pre>(rotcaesar "Ave Caesar morituri te salutant" 13)
Nir Pnrfne zbevghev gr fnyhgnag
(rotcaesar "Nir Pnrfne zbevghev gr fnyhgnag" -13)
Ave Caesar morituri te salutant</pre>