lists.arthurdejong.org
RSS feed

python-stdnum branch master updated. 1.17-9-ge2a2774

[Date Prev][Date Next] [Thread Prev][Thread Next]

python-stdnum branch master updated. 1.17-9-ge2a2774



This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "python-stdnum".

The branch, master has been updated
       via  e2a27743b3f8d57a819d8507573660fd5e0162b3 (commit)
      from  73f5e3a864915e9f3f2b01683ab9b192b4217e46 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
https://arthurdejong.org/git/python-stdnum/commit/?id=e2a27743b3f8d57a819d8507573660fd5e0162b3

commit e2a27743b3f8d57a819d8507573660fd5e0162b3
Author: Arthur de Jong <arthur@arthurdejong.org>
Date:   Mon Mar 21 14:15:32 2022 +0100

    Return check digits in 02-98 range for ISO 7064 Mod 97, 10
    
    There are some valid ranges for check digits within ISO 7064 Mod 97, 10
    that all result in a valid checksum. This changes the calculated check
    digits to be in the range from 02 to 98 as is specified for use in IBAN.
    
    See 
https://en.wikipedia.org/wiki/International_Bank_Account_Number#Generating_IBAN_check_digits
    
    Closes https://github.com/arthurdejong/python-stdnum/pull/289

diff --git a/stdnum/iso7064/mod_97_10.py b/stdnum/iso7064/mod_97_10.py
index fbc9a11..21111c3 100644
--- a/stdnum/iso7064/mod_97_10.py
+++ b/stdnum/iso7064/mod_97_10.py
@@ -1,6 +1,6 @@
 # mod_97_10.py - functions for performing the ISO 7064 Mod 97, 10 algorithm
 #
-# Copyright (C) 2010-2021 Arthur de Jong
+# Copyright (C) 2010-2022 Arthur de Jong
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
@@ -51,7 +51,7 @@ def checksum(number):
 def calc_check_digits(number):
     """Calculate the extra digits that should be appended to the number to
     make it a valid number."""
-    return '%02d' % ((98 - 100 * checksum(number)) % 97)
+    return '%02d' % (98 - checksum(number + '00'))
 
 
 def validate(number):
diff --git a/tests/test_iso7064.doctest b/tests/test_iso7064.doctest
index 28c6247..0195013 100644
--- a/tests/test_iso7064.doctest
+++ b/tests/test_iso7064.doctest
@@ -1,6 +1,6 @@
 test_doctest - more detailed doctests for the stdnum.iso7064 package
 
-Copyright (C) 2010, 2011, 2013 Arthur de Jong
+Copyright (C) 2010-2022 Arthur de Jong
 
 This library is free software; you can redistribute it and/or
 modify it under the terms of the GNU Lesser General Public
@@ -68,3 +68,14 @@ These normal tests of Mod 37, 2 should just work
 
 >>> mod_37_2.calc_check_digit('G123498654321')
 'H'
+
+
+The Mod 97, 10 check digit suggestion should prefer check digits in the
+range of 02 to 98 as is used in IBAN.
+
+>>> mod_97_10.calc_check_digits('5367')
+'02'
+>>> mod_97_10.calc_check_digits('5303')
+'97'
+>>> mod_97_10.calc_check_digits('5335')
+'98'

-----------------------------------------------------------------------

Summary of changes:
 stdnum/iso7064/mod_97_10.py |  4 ++--
 tests/test_iso7064.doctest  | 13 ++++++++++++-
 2 files changed, 14 insertions(+), 3 deletions(-)


hooks/post-receive
-- 
python-stdnum