User:Martinvl/sandbox/IBAN

Working notes start here


 * Note - text that has been struck out is legacy text that needs to be updated to reflect the new algorithm.

Working notes end here

Validating the IBAN

 * No change

Generating IBAN check digits

 * No change

Modulo operation on IBAN
Any computer programming language or software package that is used to compute D mod 97 directly must have the ability to handle integers of more than 30 digits. In practice, this can only be done by software that either supports arbitrary-precision arithmetic or that can handle 128 bit integers, features that are often not standard. If the application software in use does not provide the ability to handle integers of this size, the modulo operation can be performed in a piece-wise manner (as is the case with the UN CEFACT TBG5 Javascript program).

Piece-wise calculation D mod 97 can be done in many ways. One such way is as follows:


 * Note
 * In this algorithm, text strings are represented using upper case letters and integers by lower case letters. Thus D is a character string representation of d.
 * The conversion between integers to text and back again can be streamlined. It is done in the example to simplify the explanation.
 * If we wish to find d mod 97, proceed as follows:
 * 1. Break the string D into p pieces I1, I2, ..., Ip. The size of each piece is arbitrary, subject only to the constraint that the computer must be able to evaluate
 * I1 mod 97
 * (100 x Ik) mod 97 where k > 1.
 * 2. Define m0 as 0.
 * 3. For each segment starting with k = 1, perform the following:
 * Form the string Mk by concatenating Jk-1 and Ik
 * Set mk equal to jk mod 97
 * 4. The value mp is equal to d mod 97.

Example of IBAN check digit test
In this example, the above algorithm for evaluating d mod 97 will be applied to 321428291234 569876 5432161182 mod 97. (For clarification, the digits in green are also shown in green in the table below.) If the result is one, the IBAN corresponding to d passes the check digit test. The choice of breaking the string D into substrings each of six characters is entrely arbitrary.

In the table below:


 * Column i are numbers corresponding to the digit positions, counting from right to left.
 * Column di are the values of the digits.
 * Column ai are the progressive values calculated as ai = (ai -1 x 10) mod 97 with the initial item a1 = 1 due to the definition ai = 10(i -1) mod 97.

The values ai are independent of the IBAN being checked, i.e., they form a constant array for all check digit tests on IBANs with a certain length. The value 6 is highlighted to show the propagation of the values of mk from one row to the next.

The value in the bottom right-hand cell is the remainer when dividing 3214282912345432161182 by 97. Since it has the value 1, the IBAN passes the sanity test.