Skip to content

Instantly share code, notes, and snippets.

@codepony
Last active December 11, 2015 02:19
Show Gist options
  • Save codepony/4530170 to your computer and use it in GitHub Desktop.
Save codepony/4530170 to your computer and use it in GitHub Desktop.
Simple rot13 encoder written in CLISP.
#|
| A Simple rot13 - encoder written in CLISP
|
rot13.lisp version 0.0.1
Copyright (C) 2012 @d3f (http://identi.ca/d3f)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
| How-to:
| type in `(load "rot13.lisp") and run it with (rot13)
|#
(defparameter code-list (list))
(defparameter char-list (list))
(defun coder (input-string)
(map 'list #'make-code-list input-string)
(map 'list #'make-char-list code-list)
(format t "~%Your string in rot13: ~a~%" (concatenate 'string char-list))
(setf code-list (list))
(setf char-list (list))
)
(defun make-code-list (char)
(setf code-list (cons (char-code char) code-list))
)
(defun make-char-list (code)
(when (and (>= code 97) (<= code 122)) ;; a == 97 and z == 122, that's why we did this.
(incf code 13)
(if (> code 122)
(setf code (- code 26))
)
)
(when (and (>= code 65) (<= code 90)) ;; Same for A & Z
(incf code 13)
(if (> code 90)
(setf code (- code 26))
)
)
(setf char-list (cons (code-char code) char-list))
)
(defun rot13 ()
(format t "Type in, what you want. I will give you rot13. But `quit' will exit.~%")
(let ((str (read-line)))
(cond
((equal str "quit") (format t "Good bye ~%"))
(t (coder str) (rot13)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment