Kim Junghyun

LUHN checksum 본문

Archive/_프로그래밍

LUHN checksum

junghyun 2008. 6. 27. 13:54
Algorithm for generating the checksum digit :
 1) Format the smart card number as a decimal number, mormally unsing 11 digits.
 2) Starting with the least significant digit, multiply every 2nd digit by 2.
 3) Res = Add all individual digits in the result.
 4) Check digit = (10 - (Res MOD 10)) MOD 10.

example :
 1. smart card number = 001 4277 3428
 2. (2*0)+0+(2*1) + 4+(2*2)+7+(2*7) + 3+(2*4)+2+(2*8)
 3. Res = 0+0+2 + 4+4+7+1+4 + 3+8+2+1+6 = 42
 4. Check digit = (10 - (42 MOD 10)) MOD 10 = 8

The checksum digit is 8, so smart card number to present on screen is :
Card number : 001 4278 3428 - 8

Comments