Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;This function does most of the work!
- (defun encipher-char (ch shift)
- (let* ((c (char-code ch)) (ua (char-code #\A))
- (base (cond ((<= ua c (char-code #\Z)) ua)
- (nil))))
- (if base (code-char (+ (mod (+ (- c base) shift) 26) base)) ch)))
- ;Encrypt the plaintext
- (defun caesar-cipher (str shift)
- (map 'string #'(lambda (c) (encipher-char c shift)) str))
- ;Decrypt the plaintext
- (defun caesar-decipher (str shift) (caesar-cipher str (- shift)))
- ;Break the cipher
- (defun caesar-solve (str maxShift)
- (loop for i from 0 to maxShift
- do (let* ((solved (caesar-cipher plaintext i)))
- (format t "Solved: ~a ~%" solved))))
- ;Define some variables and print some results
- (let* ((plaintext(string-upcase "abc"))
- (shift 1)
- (maxShift 1)
- (encrypted (caesar-cipher plaintext shift))
- (decrypted (caesar-decipher encrypted shift))
- (solved (caesar-solve plaintext 26)))
- (format t " Original: ~a ~%" plaintext)
- (format t "Encrypted: ~a ~%" encrypted)
- (format t "Decrypted: ~a ~%" decrypted))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement