123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- (defvar rot13-display-table
- (let ((table (make-display-table))
- (i 0))
- (while (< i 26)
- (aset table (+ i ?a) (vector (+ (% (+ i 13) 26) ?a)))
- (aset table (+ i ?A) (vector (+ (% (+ i 13) 26) ?A)))
- (setq i (1+ i)))
- table)
- "Char table for ROT13 display.")
- (defvar rot13-translate-table
- (let ((str (make-string 127 0))
- (i 0))
- (while (< i 127)
- (aset str i i)
- (setq i (1+ i)))
- (setq i 0)
- (while (< i 26)
- (aset str (+ i ?a) (+ (% (+ i 13) 26) ?a))
- (aset str (+ i ?A) (+ (% (+ i 13) 26) ?A))
- (setq i (1+ i)))
- str)
- "String table for ROT13 translation.")
- (defun rot13 (object &optional start end)
- "Return ROT13 encryption of OBJECT, a buffer or string."
- (if (bufferp object)
- (with-current-buffer object
- (rot13-region start end))
- (rot13-string object)))
- (defun rot13-string (string)
- "Return ROT13 encryption of STRING."
- (with-temp-buffer
- (insert string)
- (rot13-region (point-min) (point-max))
- (buffer-string)))
- (defun rot13-region (start end)
- "ROT13 encrypt the region between START and END in current buffer."
- (interactive "r")
- (translate-region start end rot13-translate-table))
- (defun rot13-other-window ()
- "Display current buffer in ROT13 in another window.
- The text itself is not modified, only the way it is displayed is affected.
- To terminate the ROT13 display, delete that window. As long as that window
- is not deleted, any buffer displayed in it will become instantly encoded
- in ROT13.
- See also `toggle-rot13-mode'."
- (interactive)
- (let ((w (display-buffer (current-buffer) t)))
- (set-window-display-table w rot13-display-table)))
- (defun toggle-rot13-mode ()
- "Toggle the use of ROT13 encoding for the current window."
- (interactive)
- (if (eq (window-display-table (selected-window)) rot13-display-table)
- (set-window-display-table (selected-window) nil)
- (if (null (window-display-table (selected-window)))
- (set-window-display-table (selected-window) rot13-display-table))))
- (provide 'rot13)
|