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
Calculation of a modulo 10 control key
-
- Enthusiast
- Posts: 552
- Joined: Tue Oct 14, 2014 12:09 pm
Re: Calculation of a modulo 10 control key
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.
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.
Windows (x64)
Raspberry Pi OS (Arm64)
Raspberry Pi OS (Arm64)
- NicTheQuick
- Addict
- Posts: 1523
- Joined: Sun Jun 22, 2003 7:43 pm
- Location: Germany, Saarbrücken
- Contact:
Re: Calculation of a modulo 10 control key
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.
In all other cases: Please give us more information.
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
Re: Calculation of a modulo 10 control key
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?NicTheQuick wrote:just extract the last digit
- NicTheQuick
- Addict
- Posts: 1523
- Joined: Sun Jun 22, 2003 7:43 pm
- Location: Germany, Saarbrücken
- Contact:
Re: Calculation of a modulo 10 control key
What is a key calculation? Are we talking about private and public keys or signatures? I don't get it.
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
Re: Calculation of a modulo 10 control key
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.
You can get information about the check digit calculation methods here:
https://www.activebarcode.com/codes/che ... ulo10.html
Markus
@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")
https://www.activebarcode.com/codes/che ... ulo10.html
Markus
PB 6.12 x64, OS: Win 11 24H2 x64, Desktopscaling: 150%, CPU: I7 12700 H, RAM: 32 GB, GPU: Intel(R) Iris(R) Xe Graphics | NVIDIA GeForce RTX 3070, User age in 2025: 57y
"Happiness is a pet." | "Never run a changing system!"
"Happiness is a pet." | "Never run a changing system!"
Re: Calculation of a modulo 10 control key
Google "Luhn Formula" or "Luhn calculation"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.You can get information about the check digit calculation methods here: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")
https://www.activebarcode.com/codes/che ... ulo10.html
Markus
HP Z800 Workstation
CPU : Dual Xeon 5690 3.46GHz
RAM : 96GB RAM ( 8GB x 12 )
PSU : 1100W
GPU : NVIDIA RTX 3050 8GB
STORAGE : 9TB
(4) 2TB Seagate IronWolf Pro HDD
(1) 1TB Samsung 870 EVO SSD
CPU : Dual Xeon 5690 3.46GHz
RAM : 96GB RAM ( 8GB x 12 )
PSU : 1100W
GPU : NVIDIA RTX 3050 8GB
STORAGE : 9TB
(4) 2TB Seagate IronWolf Pro HDD
(1) 1TB Samsung 870 EVO SSD