8000 Return check digits in 02-98 range for ISO 7064 Mod 97, 10 · QuantumNovice/python-stdnum@e2a2774 · GitHub < 65F7 meta name="theme-color" content="#1e2327">
[go: up one dir, main page]

Skip to content

Commit e2a2774

Browse files
committed
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 arthurdejong#289
1 parent 73f5e3a commit e2a2774

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

stdnum/iso7064/mod_97_10.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# mod_97_10.py - functions for performing the ISO 7064 Mod 97, 10 algorithm
22
#
3-
# Copyright (C) 2010-2021 Arthur de Jong
3+
# Copyright (C) 2010-2022 Arthur de Jong
44
#
55
# This library is free software; you can redistribute it and/or
66
# modify it under the terms of the GNU Lesser General Public
@@ -51,7 +51,7 @@ def checksum(number):
5151
def calc_check_digits(number):
5252
"""Calculate the extra digits that should be appended to the number to
5353
make it a valid number."""
54-
return '%02d' % ((98 - 100 * checksum(number)) % 97)
54+
return '%02d' % (98 - checksum(number + '00'))
5555

5656

5757
def validate(number):

tests/test_iso7064.doctest

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
test_doctest - more detailed doctests for the stdnum.iso7064 package
22

3-
Copyright (C) 2010, 2011, 2013 Arthur de Jong
3+
Copyright (C) 2010-2022 Arthur de Jong
44

55
This library is free software; you can redistribute it and/or
66
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
6868

6969
>>> mod_37_2.calc_check_digit('G123498654321')
7070
'H'
71+
72+
73+
The Mod 97, 10 check digit suggestion should prefer check digits in the
74+
range of 02 to 98 as is used in IBAN.
75+
76+
>>> mod_97_10.calc_check_digits('5367')
77+
'02'
78+
>>> mod_97_10.calc_check_digits('5303')
79+
'97'
80+ 378A
>>> mod_97_10.calc_check_digits('5335')
81+
'98'

0 commit comments

Comments
 (0)
0