Vigenère cipher: Difference between revisions
Content added Content deleted
Cyril Nocton (talk | contribs) m (→Variant) |
Cyril Nocton (talk | contribs) |
||
Line 957: | Line 957: | ||
(string-upcase (remove-if-not 'alpha-char-p s))) |
(string-upcase (remove-if-not 'alpha-char-p s))) |
||
(defun vigenere (txt key &key |
(defun vigenere (txt key &key plain &aux (p (if plain -1 1))) |
||
(let ((txt (strip txt)) (key (strip key)) (i -1)) |
(let ((txt (strip txt)) (key (strip key)) (i -1)) |
||
(map 'string |
(map 'string |
||
(lambda (c) |
(lambda (c) |
||
(setf i (mod (1+ i) (length key))) |
(setf i (mod (1+ i) (length key))) |
||
(char +a+ (mod (+ (position c +a+) (* |
(char +a+ (mod (+ (position c +a+) (* p (position (elt key i) +a+))) 26))) |
||
txt)))</lang> |
txt)))</lang> |
||
Line 968: | Line 968: | ||
<pre>(vigenere "« Through the Looking-Glass »" "Lewis Carroll") |
<pre>(vigenere "« Through the Looking-Glass »" "Lewis Carroll") |
||
(vigenere "ELNWMIHKYSWZZOEVYILRJG" "Lewis Carroll" : |
(vigenere "ELNWMIHKYSWZZOEVYILRJG" "Lewis Carroll" :plain t)</pre> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |