Vigenère cipher: Difference between revisions
Content added Content deleted
Cyril Nocton (talk | contribs) m (→Main solution) |
Cyril Nocton (talk | contribs) m (→Variant) |
||
Line 947: | Line 947: | ||
dec: BEWARETHEJABBERWOCKTHEJAWSTHATTHECLAWSTHATCATCH</pre> |
dec: BEWARETHEJABBERWOCKTHEJAWSTHATTHECLAWSTHATCATCH</pre> |
||
==== |
====Alternate version==== |
||
No string to circular list conversion. |
No string to circular list conversion. |
||
Line 957: | Line 957: | ||
(string-upcase (remove-if-not 'alpha-char-p s))) |
(string-upcase (remove-if-not 'alpha-char-p s))) |
||
(defun vigenere ( |
(defun vigenere (txt key &key decode &aux (d (if decode -1 1))) |
||
(let (( |
(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+) (* d (position (elt key i) +a+))) 26))) |
(char +a+ (mod (+ (position c +a+) (* d (position (elt key i) +a+))) 26))) |
||
txt)))</lang> |
|||
2. Execution |
2. Execution |