Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/clisp
- ;;; ROT13 (rotate by 13 places) algorithm implemented Common Lisp
- ;;; Example:
- ;; CL-USER> (rot13-string "HELLO") => "URYYB"
- ;; or
- ;; [shell]$ echo 'HELLO' | clisp rot13.lisp
- ;;; Source: $EMACS/lisp/rot13.el
- ;;; Code:
- (defvar *rot13-translate-table*
- (let ((str (make-string 127 :initial-element #\NUll)))
- (dotimes (i 127)
- (setf (elt str i) (code-char i)))
- (dotimes (i 26)
- (setf (elt str (+ i #1=#.(char-code #\a)))
- (code-char (+ (mod (+ i 13) 26) #1#)))
- (setf (elt str (+ i #2=#.(char-code #\A)))
- (code-char (+ (mod (+ i 13) 26) #2#))))
- str)
- "String table for ROT13 translation.")
- (defun rot13-char (char)
- (handler-case
- (elt *rot13-translate-table* (char-int char))
- (error (e) char)))
- (defun rot13-string (string)
- (map 'string #'rot13-char string))
- (defun main ()
- (loop for line = (read-line nil nil)
- while line
- do (format t "~A~%" (rot13-string line))))
- (main)
- ;;; EOF
Add Comment
Please, Sign In to add comment