IBAN Checker with Modulo 97 Algorithm
Lets take iban number for a Central Bank of the Republic of Turkey and disect the steps.
-
Move last four to the end
TR470000100100000350930001 -> 0000100100000350930001TR47
-
Replace characters with digits
0000100100000350930001TR47 -> 0000100100000350930001292747
-
Start iteration over nine digit numbers
N = 000010010, d = N % 97 = 19
N = 19000035093, d = N % 97 = 43
N = 430001292747, d = N % 97 = 1
-
If
d == 1
then valid; otherwise invalid.
The implemention make us of a specialized "iterator" that perform step 1 and 2 without any allocations.