Advertisement
maxpolk

Emacs symmetric crypto on region

Jan 27th, 2015
399
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 1.21 KB | None | 0 0
  1. ;; Easiest symmetric crypto for region of text.
  2. ;;
  3. ;; Mark start of region, move cursor to end of region, then
  4. ;; hit either M-f11 to encrypt, or M-f12 to decrypt.
  5. ;; Try alternating between both (without moving cursor) to
  6. ;; see the text morph from cleartext to encrypted text back
  7. ;; and forth.
  8. ;; After encrypting you can copy or kill without moving cursor.
  9. ;; Or after pasting encrypted into buffer, hit M-f12 to decrypt
  10. ;; since pasted region is already marked.  Short, simple, easy.
  11.  
  12. ;; Needed for below functions
  13. (require 'epg)
  14.  
  15. ;; Encrypt region with default password
  16. (defun symmetric-encrypt-region (&optional n)
  17.   "Encrypt region using symmetric crypto."
  18.   (interactive "P")
  19.   (let ((plain (delete-and-extract-region (point) (mark))))
  20.     (insert-string (epg-encrypt-string (epg-make-context nil t) plain nil))))
  21. (global-set-key [M-f11] 'symmetric-encrypt-region)
  22.  
  23. ;; Decrypt region with default password
  24. (defun symmetric-decrypt-region (&optional n)
  25.   "Decrypt region using symmetric crypto."
  26.   (interactive "P")
  27.   (let ((cipher (delete-and-extract-region (point) (mark))))
  28.     (insert-string (epg-decrypt-string (epg-make-context nil t) cipher))))
  29. (global-set-key [M-f12] 'symmetric-decrypt-region)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement