Does anyone have a working function available to use within Oracle using PL/SQL which implements the Luhn Mod 16 Algorithm to generate a check digit for an input code number such as the following example? 0B012722900021AC35B2
LOGIC
Map from HEX into Decimal equivalent
0 B 0 1 2 7 2 2 9 0 0 0 2 1 A C 3 5 B 2- becomes0 11 0 1 2 7 2 2 9 0 0 0 2 1 10 12 3 5 11 2Start with the last character in the string and move left doubling every other number - Becomes
0 22 0 2 2 14 2 4 9 0 0 0 2 2 10 24 3 10 11 4Convert the "double" to a Base 16 (Hexadecimal) format. If the conversion results in numeric output, retain the value. Becomes:
0 16 0 2 2 E 2 4 9 0 0 0 2 2 10 18 3 A 11 4Reduce by splitting down any resultant values over a single digit in length. Becomes
0 (1+6) 0 2 2 E 2 4 9 0 0 0 2 2 10 (1+8) 3 A 11 4Sum all digits. Apply the last numeric value returned from the previous sequence of calculations (if the current value is A-F substitute the numeric value from step 1) Becomes
0 7 0 2 2 7 2 4 9 0 0 0 2 2 10 9 3 5 11 4The sum of al l digits is 79
(0+7+0+2+2+7+2+4+9+0+0+0+2+2+10+9+3+5+11+4)Calculate the value needed to obtain the next multiple of 16, in this case the next multiple 16 is 80 therefore the value is 1
The associated check character is
1
Thanks Lee
step 5)from your comment on my answer. Please check my interpretation is correct. - APC