18 lines
1,007 B
Rexx
18 lines
1,007 B
Rexx
/*REXX pgm uses H. Michael Damm's algorithm to validate numbers with suffixed check sum. digit*/
|
|
a.0= 0317598642; a.1= 7092154863; a.2= 4206871359; a.3= 1750983426; a.4= 6123045978
|
|
a.5= 3674209581; a.6= 5869720134; a.7= 8945362017; a.8= 9438617205; a.9= 2581436790
|
|
Call Damm 5724, 5727, 112946, 112940 /*invoke Damm's algorithm To some #'s.*/
|
|
Exit /*stick a Tok in it, we're all Done. */
|
|
/*---------------------------------------------------------------------------------*/
|
|
Damm:
|
|
Do j=1 To arg() /* loop over numbers */
|
|
x=arg(j)
|
|
d=0
|
|
Do p=1 To length(x)-1 /* compute the checksum digit */
|
|
d=substr(a.d,substr(x,p,1)+1,1)
|
|
end /*p*/
|
|
z=right(x,1) /* the given digit */
|
|
If z=d Then Say ' valid checksum digit ' z " for " x
|
|
Else Say ' invalid checksum digit ' z " for " x ' (should be' d")"
|
|
End /*j*/
|
|
Return
|