moduloiban

Algorithm to add two digits to the end of a number to calculate a specific modulus?


So, lets say I have a number 123456. 123456 % 97 = 72. How can I determine what two digits need to be added to the end of 123456 such that the new number % 97 = 1? Note--it must always be two digits.

For example, 12345676 % 97 = 1. In this case, I need to add the digits "76" to the end of the number.

(This is for IBAN number calculation.)


Solution

  • You calc the modulo of 12345600 to 97 and add (97 - that + 1) to that number. So you get what RoBorg explained whay cleaner above :)