Hi Friends,
Does anyone worked in Luhn algorithm or Luhn formula, also known as the "modulus 10" or "mod 10" algorithm (in Navision)?
Luhn algorithm is a simple checksum formula used to validate a variety of identification numbers, such as credit card numbers, barcodes etc., Also see this link:
http://en.wikipedia.org/wiki/Modulus_10
Am totally blank about this. Can anyone please provide me with how to handle this in Navision or with links which addresses this topic?
Thanks,
Aravindh
Comments
Ltxt_resultstring is also a text, all the other variables are integers.
The following example is from Wikipedia The sum calculated by STRCHECKSUM was 82 and therefore the check digit 8. This is because STCHECKSUM includes 18 and 16 in its sum. The Lunh algorithm, however sums up their cross sum, so adds up 1+8=9 and 1+6=7 instead.
geronimo's Code assumes an odd number of digits in it's Ptxt_String parameter to work correctly.
geronimo's code starts from the left.
Therefore it matters whether you have an even or odd number of digits to evaluate.
The code may easily be anhanced, though.
ah i must have read past that part it is indeed fairly easy to adapt the code however
Thank you guys for joining in this discussion and providing solutions and your ideas. It was useful. The client had changed the logic now which is given below.
I need to find the verification digit to the following value: 3070841326319000361243033388633240620117 (Length - 39 char)
1. Sum odd positions [3, 7, 8, 1, 2, 3, 9, 0, 3, 1, 4, 0, 3, 8, 6, 3, 4, 6, 0, 1]. (SumOdd = 72)
2. Multiply SumOdd * 3. (Mult = 72 * 3 = 216)
3. Sum even positions [0, 0, 4, 3, 6, 1, 0, 0, 6, 2, 3, 3, 3, 8, 3, 2, 0, 2, 1]. (SumEven = 47)
4. Sum = Mult + SumEven, (Sum = 216 + 47 = 263)
5. Verification digit 7. (We need to add the integer value 7 to 263 so the nearest higher value which should divisible by 10 and the remainder remains 0.)
To find the lowest number (verification digit)...:
VeriDigit = 10 - (Sum - (int(Sum/10) * 10))
VeriDigit = 10 - (263 -(int(263/10) * 10))
= 10 - (263 - (26 * 10))
= 10 - (263 - 260) = 10 - 3
VeriDigit = 7
Can anyone please help me in solving this?
Thanks in advance,
Aravindh
Please find my solution for NAV C/AL in the following post >> https://forum.mibuso.com/discussion/77912/luhn-algorithm-modulus-10-in-dynamics-nav-c-al-code-creating-a-check-digit/p1?new=1
This can easily be converted to work in Business Central AL code
Hello Aravindh,
Here is my take on a solution for your problem. It is similar to the solution I posted earlier.
I was initially confused by the results but I realized I had to take the last digit out of the number before putting it into the algorithm
But I must ask why the sum of odd numbers is multiplied by 3 specifically and is it always 3?
Anyways, here is the code below:
Variables:
Name DataType Subtype Length
i Integer
LengthOfDigit Integer
CodeCharacter Code 250
Product BigInteger
SumProduct BigInteger
SingleDigit Integer
SumOfOddNumbers Integer
SumOfEvenNumbers Integer