-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrot13.lisp
37 lines (29 loc) · 1008 Bytes
/
rot13.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/local/bin/sbcl --script
(defun help ()
(write-line
"rot13.lisp [input string]
rot13 in common lisp.
For rot13 reference, see: https://en.wikipedia.org/wiki/ROT13
")
(quit))
(defun rot13 (string)
(let ((code (flet ((alist (start end)
(let* ((seq (loop for i from start to end
collect (code-char i)))
(sub1 (subseq seq 0 13))
(sub2 (subseq seq 13)))
(append (pairlis sub1 sub2) (pairlis sub2 sub1)))))
(append (alist (char-code #\A) (char-code #\Z))
(alist (char-code #\a) (char-code #\z))))))
(map 'string
(lambda (x)
(let ((ret (cdr (assoc x code :test #'char=))))
(if (null ret) x ret)))
string)))
(defun main (args)
(unless (= 2 (length args))
(help))
(let ((str (cadr args)))
(write-line (rot13 str))
(quit)))
(main *posix-argv*)