Problem: Calculation of the check digit
Read a card file (ends with / * col 1-2) with CPF numbers and check the validity.
Calculation of the check digit of the CPF (BR – Registration physical personer), issued by the Federal Revenue Service.
The CPF number has 9 digits plus two check digits, which are indicated after a slash. Therefore, a CPF has 11 digits. The CPF number is written in the form ABCDEFGHI / JK or directly as ABCDEFGHIJK, where the figures cannot all be the same.
The J is called the 1st check digit of the CPF number.
The K is called the 2nd digit of the CPF number.
First Digit
To obtain J, we multiply A, B, C, D, E, F, G, H and I by the corresponding constants:
A B C D E F G H I x10 x9 x8 x7 x6 x5 x4 x3 x2 The result of the sum, 10A + 9B + 8C + 7D + 6E + 5F + 4G + 3H + 2I, is divided by 11.
We then analyze the REST of that division:
If it is 0 or 1, the digit J is [0] (zero). If it is 2, 3, 4, 5, 6, 7, 8, 9 or 10, the digit J is [11 – REST]
Second Digit
We already have J. To obtain K, we multiply A, B, C, D, E, F, G, H, I and J by the corresponding constants:
A B C D E F G H I J x11 x10 x9 x8 x7 x6 x5 x4 x3 x2 The result of the sum, 11A + 10B + 9C + 8D + 7E + 6F + 5G + 4H + 3I + 2J, is divided by 11.
We then verify the REST of that division:
If it is 0 or 1, the digit K is [0] (zero). If it is 2, 3, 4, 5, 6, 7, 8, 9 or 10, the K digit is [11 – REST].
Recent Comments