Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
19
Task/Caesar-cipher/Common-Lisp/caesar-cipher-1.lisp
Normal file
19
Task/Caesar-cipher/Common-Lisp/caesar-cipher-1.lisp
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
(defun encipher-char (ch key)
|
||||
(let* ((c (char-code ch)) (la (char-code #\a)) (ua (char-code #\A))
|
||||
(base (cond ((<= la c (char-code #\z)) la)
|
||||
((<= ua c (char-code #\Z)) ua)
|
||||
(nil))))
|
||||
(if base (code-char (+ (mod (+ (- c base) key) 26) base)) ch)))
|
||||
|
||||
(defun caesar-cipher (str key)
|
||||
(map 'string #'(lambda (c) (encipher-char c key)) str))
|
||||
|
||||
(defun caesar-decipher (str key) (caesar-cipher str (- key)))
|
||||
|
||||
(let* ((original-text "The five boxing wizards jump quickly")
|
||||
(key 3)
|
||||
(cipher-text (caesar-cipher original-text key))
|
||||
(recovered-text (caesar-decipher cipher-text key)))
|
||||
(format t " Original: ~a ~%" original-text)
|
||||
(format t "Encrypted: ~a ~%" cipher-text)
|
||||
(format t "Decrypted: ~a ~%" recovered-text))
|
||||
9
Task/Caesar-cipher/Common-Lisp/caesar-cipher-2.lisp
Normal file
9
Task/Caesar-cipher/Common-Lisp/caesar-cipher-2.lisp
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
(defun caesar-encipher (s k)
|
||||
(map 'string #'(lambda (c) (z c k)) s))
|
||||
|
||||
(defun caesar-decipher (s k) (caesar-encipher s (- k)))
|
||||
|
||||
(defun z (h k &aux (c (char-code h))
|
||||
(b (or (when (<= 97 c 122) 97)
|
||||
(when (<= 65 c 90) 65))))
|
||||
(if b (code-char (+ (mod (+ (- c b) k) 26) b)) h))
|
||||
9
Task/Caesar-cipher/Common-Lisp/caesar-cipher-3.lisp
Normal file
9
Task/Caesar-cipher/Common-Lisp/caesar-cipher-3.lisp
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
(defconstant +a+ "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz")
|
||||
|
||||
(defun caesar (txt offset)
|
||||
(map 'string
|
||||
#'(lambda (c)
|
||||
(if (find c +a+)
|
||||
(char +a+ (mod (+ (position c +a+) (* 2 offset)) 52))
|
||||
c))
|
||||
txt))
|
||||
Loading…
Add table
Add a link
Reference in a new issue