Luhn algorithm: Difference between revisions

Content deleted Content added
Uses: I added information about the use of the Luhn algorithm for validating Italian VAT numbers.
Description: The previous formula does not match the formula used in the example calculation.
Line 10:
# With the payload, start from the rightmost digit. Moving left, double the value of every second digit (including the rightmost digit).
# Sum the values of the resulting digits.
# The check digit is calculated by <math>(10 - (s \bmod 10)) \bmod 10</math>, where s is the sum from step 3. This is the smallest number (possibly zero) that must be added to <math>s</math> to make a multiple of 10. Other valid formulas giving the same value are <math>9 - ((s + 9)\bmod 10)</math>, <math>(10 - s)\bmod 10</math>, and <math>10\lceil s/10\rceil - s</math>. Note that the formula <math>(10 - s)\bmod 10</math> will not work in all environments due to differences in how negative numbers are handled by the [[modulo]] operation.
 
=== Example for computing check digit ===