[comp.emacs] encrypting a buffer

jr@PEBBLES.BBN.COM (John Robinson) (03/24/88)

You're close.  How about:

(defun encrypt-region (key)
"Encrypt the region after prompting for a key."
  (interactive "sDES Key: ")
  (call-process-region (region-beginning) (region-end) "des" t t nil
		       "-e" "-f" "-k" key))

(defun decrypt-region (key)
"Decrypt the region after prompting for a key."
  (interactive "sDES Key: ")
  (call-process-region (region-beginning) (region-end) "des" t t nil
		       "-d" "-f" "-k" key))

/jr
jr@bbn.com or jr@bbn.uucp

obh@IFI.UIO.NO (03/24/88)

       Sorry to post this to the net; the mailer at seismo.CSS.GOV
       didn't quite understand the receviers address.

> From: "Mark D. Grover" <seismo.CSS.GOV!sundc!potomac!grover>
> 
> Has anyone implemented a DES interface to RMAIL or to a buffer in
> general?  I may want to encrypt mail for delivery through a network
> (so 'xsend' is not the answer).  I would like a M-x encrypt-buffer and
> decrypt-buffer command (or, better, an RMAIL command that acts on the
> message).  The command would prompt for the key.  I am using a Sun.
> 
> Using "ESC | des" produces output that fails to decrypt.  Any ideas?
> 

(defun do-crypt-region (start end key)
  "runs des -e on the region and replace it's contents with des output"
  (interactive "r\nsEnter Key: ")
  (call-process-region start end "des" t t t
  ;;The arguments to the des program
  "-e" "-k" key))

(defun encrypt-mail (key)
  (interactive "sEnter Key: ")
  (save-excursion
    (goto-char (point-min))
    (search-forward "\n--text follows this line--\n")
    (do-crypt-region (point) (point-max) key)))

(defun do-decrypt-region (start end key)
  "runs des -e on the region and replace it's contents with des output"
  (interactive "r\nsEnter Key: ")
  (call-process-region start end "des" t t t
  ;;The arguments to the des program
  "-d" "-k" key))

(defun decrypt-mail (key)
  (interactive "sEnter Key: ")
  (save-excursion
    (goto-char (point-min))
    (search-forward "\n--text follows this line--\n")
    (do-decrypt-region (point) (point-max) key)))

This hack should do the right thing. I've not tested it thoroughly but
it worked on this mail when I used the crypt program. (Hopefully I gave
``des'' the righ args) It's not a safe program, but your're safe from the
postmasters ;-)

	Hope it works!

Ole Bjoern Hessen					(OBH)
obh@ifi.uio.no