Jump to content

Vigenère cipher: Difference between revisions

Line 957:
(string-upcase (remove-if-not 'alpha-char-p s)))
 
(defun vigenere (txt key &key decodeplain &aux (dp (if decodeplain -1 1)))
(let ((txt (strip txt)) (key (strip key)) (i -1))
(map 'string
(lambda (c)
(setf i (mod (1+ i) (length key)))
(char +a+ (mod (+ (position c +a+) (* dp (position (elt key i) +a+))) 26)))
txt)))</lang>
 
Line 968:
 
<pre>(vigenere "« Through the Looking-Glass »" "Lewis Carroll")
(vigenere "ELNWMIHKYSWZZOEVYILRJG" "Lewis Carroll" :decodeplain t)</pre>
{{out}}
<pre>
422

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.