I'm building a calculator for International Bank Account Numbers (IBAN) but I'm having trouble calculating the modulus for a big number. That is to say, my results are not the same as that of the examples I have.
To calculate the IBAN checksum I have to follow these steps (taken from WikiPedia):
- Replace the two check digits by 00 (e.g., GB00 for the UK).
- Move the four initial characters to the end of the string.
- Replace the letters in the string with digits, expanding the string as necessary, such that A or a=10, B or b=11 and Z or z=35. Each alphabetic character is therefore replaced by 2 digits.
- Convert the string to an integer (i.e., ignore leading zeroes).
- Calculate Mod-97 of the new number.
- Subtract the remainder from 98 and, if necessary, pad with a leading 0 to make a two digit number.
For example NL20INGB0001234567
- 182316110001234567232100 % 97 = 67
- 98 - 67 = 31
Since 31 does not equal 20 I conclude that something went wrong. According to an example 182316110001234567232100 % 97 should yield 78 but I don't see how.
What am I doing wrong in my modulus calculation?