| 1 | ;;; mule-caesar.el --- ROT 13-47 Caesar rotation utility |
|---|
| 2 | |
|---|
| 3 | ;; Copyright (C) 1997,1998 Free Software Foundation, Inc. |
|---|
| 4 | |
|---|
| 5 | ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp> |
|---|
| 6 | ;; Keywords: ROT 13-47, caesar, mail, news, text/x-rot13-47 |
|---|
| 7 | |
|---|
| 8 | ;; This file is part of APEL (A Portable Emacs Library). |
|---|
| 9 | |
|---|
| 10 | ;; This program is free software; you can redistribute it and/or |
|---|
| 11 | ;; modify it under the terms of the GNU General Public License as |
|---|
| 12 | ;; published by the Free Software Foundation; either version 2, or (at |
|---|
| 13 | ;; your option) any later version. |
|---|
| 14 | |
|---|
| 15 | ;; This program is distributed in the hope that it will be useful, but |
|---|
| 16 | ;; WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 17 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|---|
| 18 | ;; General Public License for more details. |
|---|
| 19 | |
|---|
| 20 | ;; You should have received a copy of the GNU General Public License |
|---|
| 21 | ;; along with GNU Emacs; see the file COPYING. If not, write to the |
|---|
| 22 | ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
|---|
| 23 | ;; Boston, MA 02111-1307, USA. |
|---|
| 24 | |
|---|
| 25 | ;;; Code: |
|---|
| 26 | |
|---|
| 27 | (require 'emu) ; for backward compatibility. |
|---|
| 28 | (require 'poe) ; char-after. |
|---|
| 29 | (require 'poem) ; charset-chars, char-charset, |
|---|
| 30 | ; and split-char. |
|---|
| 31 | |
|---|
| 32 | (defun mule-caesar-region (start end &optional stride-ascii) |
|---|
| 33 | "Caesar rotation of current region. |
|---|
| 34 | Optional argument STRIDE-ASCII is rotation-size for Latin alphabet |
|---|
| 35 | \(A-Z and a-z). For non-ASCII text, ROT-N/2 will be performed in any |
|---|
| 36 | case (N=charset-chars; 94 for 94 or 94x94 graphic character set; 96 |
|---|
| 37 | for 96 or 96x96 graphic character set)." |
|---|
| 38 | (interactive "r\nP") |
|---|
| 39 | (setq stride-ascii (if stride-ascii |
|---|
| 40 | (mod stride-ascii 26) |
|---|
| 41 | 13)) |
|---|
| 42 | (save-excursion |
|---|
| 43 | (save-restriction |
|---|
| 44 | (narrow-to-region start end) |
|---|
| 45 | (goto-char start) |
|---|
| 46 | (while (< (point)(point-max)) |
|---|
| 47 | (let* ((chr (char-after (point)))) |
|---|
| 48 | (cond ((and (<= ?A chr) (<= chr ?Z)) |
|---|
| 49 | (setq chr (+ chr stride-ascii)) |
|---|
| 50 | (if (> chr ?Z) |
|---|
| 51 | (setq chr (- chr 26)) |
|---|
| 52 | ) |
|---|
| 53 | (delete-char 1) |
|---|
| 54 | (insert chr) |
|---|
| 55 | ) |
|---|
| 56 | ((and (<= ?a chr) (<= chr ?z)) |
|---|
| 57 | (setq chr (+ chr stride-ascii)) |
|---|
| 58 | (if (> chr ?z) |
|---|
| 59 | (setq chr (- chr 26)) |
|---|
| 60 | ) |
|---|
| 61 | (delete-char 1) |
|---|
| 62 | (insert chr) |
|---|
| 63 | ) |
|---|
| 64 | ((<= chr ?\x9f) |
|---|
| 65 | (forward-char) |
|---|
| 66 | ) |
|---|
| 67 | (t |
|---|
| 68 | (let* ((stride (lsh (charset-chars (char-charset chr)) -1)) |
|---|
| 69 | (ret (mapcar (function |
|---|
| 70 | (lambda (octet) |
|---|
| 71 | (if (< octet 80) |
|---|
| 72 | (+ octet stride) |
|---|
| 73 | (- octet stride) |
|---|
| 74 | ))) |
|---|
| 75 | (cdr (split-char chr))))) |
|---|
| 76 | (delete-char 1) |
|---|
| 77 | (insert (make-char (char-charset chr) |
|---|
| 78 | (car ret)(car (cdr ret)))) |
|---|
| 79 | ))) |
|---|
| 80 | ))))) |
|---|
| 81 | |
|---|
| 82 | |
|---|
| 83 | (require 'product) |
|---|
| 84 | (product-provide (provide 'mule-caesar) (require 'apel-ver)) |
|---|
| 85 | |
|---|
| 86 | ;;; mule-caesar.el ends here |
|---|