checkdigit calculation for HP-17b
|
07-28-2015, 08:28 PM
Post: #18
|
|||
|
|||
RE: checkdigit calculation for HP-17b
(07-28-2015 06:48 PM)Gerson W. Barbosa Wrote: It intrigues me a bit why this more simple algorithm works From Cadastro de Pessoas Físicas Code: v[1] := (1×cpf[1] + 2×cpf[2] + 3×cpf[3] + 4×cpf[4] + 5×cpf[5] + 6×cpf[6] + 7×cpf[7] + 8×cpf[8] + 9×cpf[9]) mod 11 Code: v[2] := (9×(1×cpf[1] + 2×cpf[2] + 3×cpf[3] + 4×cpf[4] + 5×cpf[5] + 6×cpf[6] + 7×cpf[7] + 8×cpf[8] + 9×cpf[9]) + We can do the multiplication by 9 mod 11: Code: v[2] := (9×cpf[1] + 7×cpf[2] + 5×cpf[3] + 3×cpf[4] + 1×cpf[5] - 1×cpf[6] - 3×cpf[7] - 5×cpf[8] - 7×cpf[9] + This gives us: Code: v[2] := (9×cpf[1] + 8×cpf[2] + 7×cpf[3] + 6×cpf[4] + 5×cpf[5] + 4×cpf[6] + 3×cpf[7] + 2×cpf[8] + 1×cpf[9]) mod 11 But then you will say that v[1] wasn't calculated correctly: Code: v[1] := v[1] mod 11 Thus in case that v[1] = 10 we will get 0 instead of 10. This is corrected with this step in your program: Code: t:=t+9*((s Mod 11) div 10); Kind regards Thomas |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)