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.
source share