Check Sum
Bill Marriott
wjm at wjm.org
Mon Apr 23 09:45:48 EDT 2007
Rev has the function md5digest; you could take the last digit of that; but
from a processing point of view it might be overkill.
I looked up "check digit" in Wikipedia. It seems one popular check digit is
"UPC." From Wikipedia:
>>>
The final digit of a Universal Product Code is a check digit computed as
follows:
1. Add the digits in the odd-numbered positions (first, third, fifth, etc.)
together and multiply by three.
2. Add the digits in the even-numbered positions (second, fourth, sixth,
etc.) to the result.
3. Subtract the result from the next-higher multiple of ten. The answer is
the check digit.
For instance, a UPC-A barcode (In this case, a UPC for a box of tissues)
"03600029145X" where X is the check digit, X can be calculated by adding the
odd-numbered digits (0+6+0+2+1+5 = 14), multiplying by three (14 × 3 = 42),
adding the even-numbered digits (42+3+0+0+9+4 = 58) and subtracting from the
next-highest multiple of ten (60 - 58 = 2). The check digit is thus 2.
<<<
function upcCheck pValue
repeat with i = 1 to the length of pValue step 2
add char i of pValue to x
end repeat
multiply x by 3
repeat with i = 2 to the length of pValue step 2
add char i of pValue to x
end repeat
return 10 - ( x mod 10 )
end upcCheck
"Scott Kane" <scott at cdroo.com> wrote in
message news:019801c78596$6128c940$0201010a at esbgdi9s3atqpx...
> Hi people,
>
> Been reading some of the great scripts online for Rev for encryption and
> hashing etc. One thing I've not been able to find (checked the doc's) is
> a method to generate (and check) a check digit. I can do this in assembly
> just fine (not much use in Rev unless I code an external which for
> security reasons I don't want to do). Is there a method I've missed that
> would allow a number (hex aware preferably) that allows one to do this?
>
> Note that the results I manage to glean for this will be published in an
> article for the Revolution newsletter in regards to license systems and
> anti piracy measures. I have a system in Delphi and C++ that I wish to
> translate into Rev and then share the results within that article
> (including code).
>
> Scott
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-revolution
>
More information about the use-livecode
mailing list