;;; decipher.el --- cryptanalyze monoalphabetic substitution ciphers
;;
-;; Copyright (C) 1995, 1996, 2001, 2002, 2003, 2004,
-;; 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+;; Copyright (C) 1995-1996, 2001-2011 Free Software Foundation, Inc.
;;
;; Author: Christopher J. Madsen <chris_madsen@geocities.com>
;; Keywords: games
:group 'games)
(defcustom decipher-force-uppercase t
- "*Non-nil means to convert ciphertext to uppercase.
+ "Non-nil means to convert ciphertext to uppercase.
nil means the case of the ciphertext is preserved.
This variable must be set before typing `\\[decipher]'."
:type 'boolean
(defcustom decipher-ignore-spaces nil
- "*Non-nil means to ignore spaces and punctuation when counting digrams.
+ "Non-nil means to ignore spaces and punctuation when counting digrams.
You should set this to nil if the cipher message is divided into words,
or t if it is not.
This variable is buffer-local."
'bold)))
in your `.emacs' file.")
-(defvar decipher-mode-map nil
+(defvar decipher-mode-map
+ (let ((map (make-keymap)))
+ (suppress-keymap map)
+ (define-key map "A" 'decipher-show-alphabet)
+ (define-key map "C" 'decipher-complete-alphabet)
+ (define-key map "D" 'decipher-digram-list)
+ (define-key map "F" 'decipher-frequency-count)
+ (define-key map "M" 'decipher-make-checkpoint)
+ (define-key map "N" 'decipher-adjacency-list)
+ (define-key map "R" 'decipher-restore-checkpoint)
+ (define-key map "U" 'decipher-undo)
+ (define-key map " " 'decipher-keypress)
+ (define-key map [remap undo] 'decipher-undo)
+ (define-key map [remap advertised-undo] 'decipher-undo)
+ (let ((key ?a))
+ (while (<= key ?z)
+ (define-key map (vector key) 'decipher-keypress)
+ (incf key)))
+ map)
"Keymap for Decipher mode.")
-(if (not decipher-mode-map)
- (progn
- (setq decipher-mode-map (make-keymap))
- (suppress-keymap decipher-mode-map)
- (define-key decipher-mode-map "A" 'decipher-show-alphabet)
- (define-key decipher-mode-map "C" 'decipher-complete-alphabet)
- (define-key decipher-mode-map "D" 'decipher-digram-list)
- (define-key decipher-mode-map "F" 'decipher-frequency-count)
- (define-key decipher-mode-map "M" 'decipher-make-checkpoint)
- (define-key decipher-mode-map "N" 'decipher-adjacency-list)
- (define-key decipher-mode-map "R" 'decipher-restore-checkpoint)
- (define-key decipher-mode-map "U" 'decipher-undo)
- (define-key decipher-mode-map " " 'decipher-keypress)
- (define-key decipher-mode-map [remap undo] 'decipher-undo)
- (define-key decipher-mode-map [remap advertised-undo] 'decipher-undo)
- (let ((key ?a))
- (while (<= key ?z)
- (define-key decipher-mode-map (vector key) 'decipher-keypress)
- (incf key)))))
-
-(defvar decipher-stats-mode-map nil
- "Keymap for Decipher-Stats mode.")
-(if (not decipher-stats-mode-map)
- (progn
- (setq decipher-stats-mode-map (make-keymap))
- (suppress-keymap decipher-stats-mode-map)
- (define-key decipher-stats-mode-map "D" 'decipher-digram-list)
- (define-key decipher-stats-mode-map "F" 'decipher-frequency-count)
- (define-key decipher-stats-mode-map "N" 'decipher-adjacency-list)
- ))
+
+
+(defvar decipher-stats-mode-map
+ (let ((map (make-keymap)))
+ (suppress-keymap map)
+ (define-key map "D" 'decipher-digram-list)
+ (define-key map "F" 'decipher-frequency-count)
+ (define-key map "N" 'decipher-adjacency-list)
+ map)
+"Keymap for Decipher-Stats mode.")
+
(defvar decipher-mode-syntax-table nil
"Decipher mode syntax table")
(insert ">\n"))))) ;Mark plaintext line
(delete-blank-lines) ;Remove any blank lines
(delete-blank-lines)) ; at end of buffer
- (goto-line 4)
+ (goto-char (point-min))
+ (forward-line 3)
(decipher-mode))
;;;###autoload
(let ((font-lock-fontify-region-function 'ignore))
;; insert-and-inherit will pick the right face automatically
(while (search-forward-regexp "^:" nil t)
- (setq bound (save-excursion (end-of-line) (point)))
+ (setq bound (point-at-eol))
(while (search-forward cipher-string bound 'end)
(decipher-insert plain-char)))))))
(interactive (list (upcase (following-char))))
(decipher-analyze)
(let (start end)
- (save-excursion
- (set-buffer (decipher-stats-buffer))
+ (with-current-buffer (decipher-stats-buffer)
(goto-char (point-min))
(or (re-search-forward (format "^%c: " cipher-char) nil t)
(error "Character `%c' is not used in ciphertext" cipher-char))
END-REGEXP matches the line after that which ends the display.
The ending line is included in the display unless it is blank."
(let (start end)
- (save-excursion
- (set-buffer (decipher-stats-buffer))
+ (with-current-buffer (decipher-stats-buffer)
(goto-char (point-min))
(re-search-forward start-regexp)
(beginning-of-line)
(aref decipher--after i)))
freq-list)
total-chars (+ total-chars (aref decipher--freqs i)))))
- (save-excursion
- ;; Switch to statistics buffer, creating it if necessary:
- (set-buffer (decipher-stats-buffer t))
+ ;; Switch to statistics buffer, creating it if necessary:
+ (with-current-buffer (decipher-stats-buffer t)
;; This can't happen, but it never hurts to double-check:
(or (eq major-mode 'decipher-stats-mode)
(error "Buffer %s is not in Decipher-Stats mode" (buffer-name)))
;; See if decipher-stats-buffer exists:
((and (bufferp decipher-stats-buffer)
(buffer-name decipher-stats-buffer))
- (or (save-excursion
- (set-buffer decipher-stats-buffer)
+ (or (with-current-buffer decipher-stats-buffer
(eq major-mode 'decipher-stats-mode))
(error "Buffer %s is not in Decipher-Stats mode"
(buffer-name decipher-stats-buffer)))
;; We just lost track of the statistics buffer:
(get-buffer stats-name)
(generate-new-buffer stats-name))))
- (save-excursion
- (set-buffer decipher-stats-buffer)
+ (with-current-buffer decipher-stats-buffer
(decipher-stats-mode))
decipher-stats-buffer)
;; Give up:
(provide 'decipher)
-;;;(defun decipher-show-undo-list ()
-;;; "Display the undo list (for debugging purposes)."
-;;; (interactive)
-;;; (with-output-to-temp-buffer "*Decipher Undo*"
-;;; (let ((undo-list decipher-undo-list)
-;;; undo-rec undo-map)
-;;; (save-excursion
-;;; (set-buffer "*Decipher Undo*")
-;;; (while (setq undo-rec (pop undo-list))
-;;; (or (consp (car undo-rec))
-;;; (setq undo-rec (list undo-rec)))
-;;; (insert ?\()
-;;; (while (setq undo-map (pop undo-rec))
-;;; (insert (cdr undo-map) (car undo-map) ?\ ))
-;;; (delete-backward-char 1)
-;;; (insert ")\n"))))))
-
-;; arch-tag: 8f094d88-ffe1-4f99-afe3-a5e81dd939d9
+;;(defun decipher-show-undo-list ()
+;; "Display the undo list (for debugging purposes)."
+;; (interactive)
+;; (with-output-to-temp-buffer "*Decipher Undo*"
+;; (let ((undo-list decipher-undo-list)
+;; undo-rec undo-map)
+;; (with-current-buffer "*Decipher Undo*"
+;; (while (setq undo-rec (pop undo-list))
+;; (or (consp (car undo-rec))
+;; (setq undo-rec (list undo-rec)))
+;; (insert ?\()
+;; (while (setq undo-map (pop undo-rec))
+;; (insert (cdr undo-map) (car undo-map) ?\ ))
+;; (delete-char -1)
+;; (insert ")\n"))))))
+
;;; decipher.el ends here