From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Ian Dunn Newsgroups: gmane.emacs.devel Subject: [ELPA] New package: vigenere Date: Sun, 27 Aug 2017 11:43:40 -0400 Message-ID: <87o9r1dnir.fsf@escafil> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1503848708 21044 195.159.176.226 (27 Aug 2017 15:45:08 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 27 Aug 2017 15:45:08 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Aug 27 17:45:02 2017 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dlzk4-0004X8-PI for ged-emacs-devel@m.gmane.org; Sun, 27 Aug 2017 17:44:52 +0200 Original-Received: from localhost ([::1]:33069 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dlzk8-0004rW-Fi for ged-emacs-devel@m.gmane.org; Sun, 27 Aug 2017 11:44:56 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:40360) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dlzjU-0004rL-Ib for emacs-devel@gnu.org; Sun, 27 Aug 2017 11:44:17 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dlzjT-0000kp-G9 for emacs-devel@gnu.org; Sun, 27 Aug 2017 11:44:16 -0400 Original-Received: from fencepost.gnu.org ([2001:4830:134:3::e]:54318) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dlzjT-0000ki-A5 for emacs-devel@gnu.org; Sun, 27 Aug 2017 11:44:15 -0400 Original-Received: from [2604:6000:1010:176:da4d:3352:bae5:f50e] (port=44850 helo=escafil) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1dlzjS-00029M-U1 for emacs-devel@gnu.org; Sun, 27 Aug 2017 11:44:15 -0400 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:4830:134:3::e X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:217847 Archived-At: --=-=-= Content-Type: text/plain I'd like to submit vigenere.el to ELPA. It's a single-file package to run a vigenere cipher[1] on a block of text. If no one's got any objections, I'll add the package and copyright headers and push it to the git repo. [1]https://en.wikipedia.org/wiki/Vigen%C3%A8re_cipher --=-=-= Content-Type: application/emacs-lisp Content-Disposition: attachment; filename=vigenere.el Content-Transfer-Encoding: quoted-printable ;;; vigenere.el --- Run a vigenere cipher on a block of text ; -*- lexical-= binding: t; -*- ;; Author: Ian Dunn ;; Version: 1.0 ;;; Commentary: ;; A vigenere cipher is similar to a series of shift ciphers. A key is rep= eated ;; through the plain text, then a shift cipher is used for each letter depe= nding ;; on the letter in the key at that position. ;; Example: ;; The following uses the key EMACS (because what else would my example key= be?). ;; Plain text: This is some plain text ;; First, we repeat the key through the plain text ;; This is some plain text ;; EMAC SE MACS EMACS EMAC ;; Then each letter in the plain text is shifted based on the key character= at ;; that point: ;; This is some plain text ;; EMAC SE MACS EMACS EMAC ;; Xtiu aw eoow txakf xqxv ;; The specific shift amount for each character is the 0-based offset from = A. ;; Therefore, A is 0, B is 1, etc. ;; The key in our case is case-insensitive. EMACS is Emacs is emacs is EmA= Cs. ;; One more note, is that this package only operates on letters, and the ca= se of ;; the original text is preserved. ;;; Code: (defun vigenere-process-region (key begin end enc-or-dec) "Process the region from BEGIN to END in the current buffer using KEY. ENC-OR-DEC is either 'encrypt or 'decrypt, which determines the mode of operation. KEY is case-insensitive, and case is preserved in the original text." (save-excursion (goto-char begin) (let ((key-pos 0) (key-len (length key)) (op (if (eq enc-or-dec 'encrypt) '+ '-))) ;; Only operate on letters. (while (re-search-forward "[[:alpha:]]" end t) (let* ((c (- (string-to-char (downcase (match-string-no-properties = 0))) ?a)) (k (- (string-to-char (downcase (substring key key-pos))) ?a= )) (d (char-to-string (+ (mod (funcall op c k) 26) ?a))) (case-fold-search nil)) (replace-match d)) ;; Update position in key (setq key-pos (mod (1+ key-pos) key-len)))))) (defun vigenere-decrypt-region (key begin end) "Decrypt region from BEGIN to END using KEY." (interactive "sKey:\nr") (vigenere-process-region key begin end 'decrypt)) (defun vigenere-encrypt-region (key begin end) "Encrypt region from BEGIN to END using KEY." (interactive "sKey:\nr") (vigenere-process-region key begin end 'encrypt)) (defun vigenere-decrypt-buffer (key) "Decrypt buffer using KEY." (interactive "sKey: ") (vigenere-decrypt-region key (point-min) (point-max))) (defun vigenere-encrypt-buffer (key) "Encrypt buffer using KEY." (interactive "sKey: ") (vigenere-encrypt-region key (point-min) (point-max))) (defun vigenere-decrypt-string (key string) "Decrypt STRING with KEY." (with-temp-buffer (insert string) (vigenere-decrypt-buffer key) (buffer-string))) (defun vigenere-encrypt-string (key string) "Encrypt STRING with KEY." (with-temp-buffer (insert string) (vigenere-encrypt-buffer key) (buffer-string))) (provide 'vigenere) ;;; vigenere.el ends here --=-=-= Content-Type: text/plain -- Ian Dunn --=-=-=--