Page 1 of 1
Calculation of a modulo 10 control key
Posted: Fri Oct 23, 2020 11:52 am
by loulou2522
I am looking for an example that allows the calculation of a key from a modulo 10 example.
210000000003139471430009017
the result is 7 (position 27 of the figure)
Thank you in advance for helping me
Re: Calculation of a modulo 10 control key
Posted: Fri Oct 23, 2020 12:28 pm
by wilbert
What type of numbers do you have ?
Internal formats PB supports like Quad or Double aren't suitable for this kind of large integer values.
If they are strings, you can just take the last character.
Re: Calculation of a modulo 10 control key
Posted: Fri Oct 23, 2020 3:30 pm
by NicTheQuick
If your numbers are already represented as decimal strings then just extract the last digit and there you go.
In all other cases: Please give us more information.
Re: Calculation of a modulo 10 control key
Posted: Sat Oct 24, 2020 1:25 am
by BarryG
NicTheQuick wrote:just extract the last digit
Surely that's not always going to be the case? We're talking key calculations here. The 7 in the original post was just an example for that specific calculation, no?
Re: Calculation of a modulo 10 control key
Posted: Sat Oct 24, 2020 12:02 pm
by NicTheQuick
What is a key calculation? Are we talking about private and public keys or signatures? I don't get it.
Re: Calculation of a modulo 10 control key
Posted: Sat Oct 24, 2020 6:02 pm
by Kurzer
Nic, I suspect that he means a so called "check digit calculation" (in german "Prüfziffernberechnung").
@loulou2522:
This is a modulo 10 checksum calculation with weighting 2.
Code: Select all
Procedure.s CalcChecksum(sNumber.s)
Protected.i i, iDigit, iSum, iLen
iLen = Len(sNumber)
iSum = 0
For i = 1 To iLen
iDigit = Val(Mid(sNumber, i, 1))
If i % 2 = 0 : iDigit * 2 : EndIf
iSum + iDigit
Next i
ProcedureReturn Str((10 - iSum % 10) %10)
EndProcedure
Debug CalcChecksum("21000000000313947143000901")
You can get information about the check digit calculation methods here:
https://www.activebarcode.com/codes/che ... ulo10.html
Markus
Re: Calculation of a modulo 10 control key
Posted: Mon Nov 02, 2020 2:02 am
by Mohawk70
kurzer wrote:Nic, I suspect that he means a so called "check digit calculation" (in german "Prüfziffernberechnung").
@loulou2522:
This is a modulo 10 checksum calculation with weighting 2.
Code: Select all
Procedure.s CalcChecksum(sNumber.s)
Protected.i i, iDigit, iSum, iLen
iLen = Len(sNumber)
iSum = 0
For i = 1 To iLen
iDigit = Val(Mid(sNumber, i, 1))
If i % 2 = 0 : iDigit * 2 : EndIf
iSum + iDigit
Next i
ProcedureReturn Str((10 - iSum % 10) %10)
EndProcedure
Debug CalcChecksum("21000000000313947143000901")
You can get information about the check digit calculation methods here:
https://www.activebarcode.com/codes/che ... ulo10.html
Markus
Google "Luhn Formula" or "Luhn calculation"