From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Emanuel Berg via "Emacs development discussions." Newsgroups: gmane.emacs.devel,gmane.emacs.help Subject: Re: verify ISSN (issn-verify.el) Date: Sat, 12 Sep 2020 06:04:05 +0200 Message-ID: <87v9gjbpze.fsf@ebih.ebihd> References: <87r1r96len.fsf@ebih.ebihd> <87h7s47rhp.fsf@ebih.ebihd> Reply-To: Emanuel Berg Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="8382"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) Cc: help-gnu-emacs@gnu.org To: emacs-devel@gnu.org Cancel-Lock: sha1:yKQdNpZ2+DJI6HKH1nOFJSD+X54= Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sat Sep 12 06:04:59 2020 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kGwmZ-00023w-4E for ged-emacs-devel@m.gmane-mx.org; Sat, 12 Sep 2020 06:04:59 +0200 Original-Received: from localhost ([::1]:57484 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kGwmY-0003qd-6F for ged-emacs-devel@m.gmane-mx.org; Sat, 12 Sep 2020 00:04:58 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:37440) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kGwly-0003R3-E8 for emacs-devel@gnu.org; Sat, 12 Sep 2020 00:04:22 -0400 Original-Received: from static.214.254.202.116.clients.your-server.de ([116.202.254.214]:44804 helo=ciao.gmane.io) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kGwlw-0005xu-M9 for emacs-devel@gnu.org; Sat, 12 Sep 2020 00:04:22 -0400 Original-Received: from list by ciao.gmane.io with local (Exim 4.92) (envelope-from ) id 1kGwlt-0001JB-EH for emacs-devel@gnu.org; Sat, 12 Sep 2020 06:04:17 +0200 X-Injected-Via-Gmane: http://gmane.org/ Mail-Followup-To: emacs-devel@gnu.org Original-Followup-To: gmane.emacs.help Mail-Copies-To: never Received-SPF: pass client-ip=116.202.254.214; envelope-from=ged-emacs-devel@m.gmane-mx.org; helo=ciao.gmane.io X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/11 23:46:54 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -15 X-Spam_score: -1.6 X-Spam_bar: - X-Spam_report: (-1.6 / 5.0 requ) BAYES_00=-1.9, HEADER_FROM_DIFFERENT_DOMAINS=0.25, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 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-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:255268 gmane.emacs.help:124025 Archived-At: ;;; issn-verify.el --- verify ISSN -*- lexical-binding: t ;; ;;; Commentary: ;; ;; This Elisp package provides functions to verify ;; ISSN by computing their check digits. ;; ;; Author: Emanuel Berg (incal) ;; Created: 2020-09-06 ;; Keywords: bib, tex ;; License: GPL3+ ;; Package-Requires: ((cl-lib "1.0")) ;; URL: https://dataswamp.org/~incal/emacs-init/issn-verify.el ;; Version: 1.0.0 ;; ;; Also see: ;; ;; https://dataswamp.org/~incal/emacs-init/isbn-verify.el ;; ;; To install this package, with this file in ;; a buffer, do: ;; ;; M-x load-file RET RET ;; ;; International Standard Serial Number: ;; ;; ISO 3297, 1975 ;; ;; format: ;; ;; The Ring Magazine: ISSN 0035-5410 ;; d_1d_2d_3d_4-d_5d_6d_7c ;; d_i for i \in [1, 7] is an integer ;; c, the check digit, is 0..9 or X for 10 ;; ;; compute check digit c: ;; ;; c' = 8d_1*7d_2*6d_3*5d_4*4d_5*3d_6*2d_7 mod 11 ;; ;; { 0 c' = 0 ;; c = { ;; { 11 - c' else ;; ;;; Code: (require 'cl-lib) (defun issn--get-digits (issn) (let ((check-format (string-match "[[:digit:]]\\{4\\}-[[:digit:]]\\{3\\}[X[:digit:]]" issn) )) (if (and (= 9 (length issn)) check-format (zerop check-format) ) (let*((no-dash (replace-regexp-in-string "-" "" issn)) (issn-list (string-to-list no-dash)) (c-prop (car (last issn-list))) (c-prop-x (if (equal "X" c-prop) c-prop (- c-prop ?0))) (7-1st (butlast issn-list)) (nums (mapcar (lambda (c) (- c ?0)) 7-1st)) ) (append nums `(,c-prop-x)) ) (error "Malformed ISSN") ))) (defun issn-verify (issn) (let*((issn-lst (issn--get-digits issn)) (c-prop (car (last issn-lst))) (c-w (cl-loop with cwl = 0 for d in issn-lst for w downfrom 8 to 2 do (cl-incf cwl (* w d)) finally return cwl) ) (c-prime (mod c-w 11)) (c (if (zerop c-prime) 0 (- 11 c-prime) )) (c-x (if (= 10 c) "X" c)) ) (if (equal c-prop c-x) (message "%s (OK)" c-x) (message "NOT OK! is %s, should be %s" c-prop c-x) ))) ;; Bicycle Quarterly (issn-verify "1941-8809") ; 9 (OK) ;; Bicycling (issn-verify "1651-9744") ; 4 (OK) ;; Black Belt (issn-verify "0277-3066") ; 6 (OK) ;; Filter (issn-verify "1654-9813") ; 3 (OK) ;; Linux Pro (issn-verify "1471-5679") ; NOT OK! is 9, should be 8 ;; National Geographic (issn-verify "2535-41241") ; Malformed ISSN ;; Outside (issn-verify "0278-433") ; Malformed ISSN ;; The Economist (issn-verify "0013-06a4") ; Malformed ISSN ;; The Ring (issn-verify "0035x5410") ; Malformed ISSN (provide 'issn-verify) ;;; issn-verify.el ends here -- underground experts united http://user.it.uu.se/~embe8573 https://dataswamp.org/~incal