What should I use as a check digit algorithm for a base value of 31?

I use the following set of values ​​to create a long base value of 9 characters:
0123456789ABCDEFGHJKLMNPQRTUWXY

I was looking for a modification of the Moon algorithm to work with my database.

My question is:

In base 10, the Moon algorithm doubles each value in an even position, and then, if the result is> 10, the individual digits of the result are added together.

Should I still double my even position values ​​or use a higher multiplier?

I am trying to protect against transposed characters, missing characters, extra characters and just plain numbers.

+4
source share
2 answers

I looked at the Luhn mod N algorithm, but it is very limited in what it can test.

I decided to use a modified version of the container container system.

The container shipping system multiplies each value by 2 ^ [position] (position starting at 0) and then executes module 11 of the result to obtain a check digit for base 10 (result not recommended 10).

In this case, the trick is to find values ​​in the range x ^ 0 to x ^ [length], which are unevenly divided by the shape you use on the module.

I decided to use 3 ^ [position] as a multiplier and execute module 31 for the sum to get a check digit.

As an example: 0369CFJMK

Character 0 3 6 9 CFJMK Value 0 3 6 9 12 15 18 21 19 -------------------------------------------------------------- Multiplier 1 3 9 27 81 243 729 2187 Result 0 9 54 243 972 3645 13122 45927 Total 63972 MOD 31 = 19 

It seems that with the help of such algorithms, the main requirement is that the multiplier does not divide evenly the base and that the residual pattern does not repeat within the length of the code you want to check.

+3
source

Do not reinvent the wheel - use Luhn mod N.

+2
source

All Articles