ID card code and verification code calculation rules

ID code rules

According to the regulations on citizen identity number in the "National Standard of the People's Republic of China GB11643-1999" (reference, there may be updates), the citizen identity number is a feature combination code with a total of 18 digits, consisting of a 17-digit digital body code and a digital check code.

1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8
Coding category coded digits ranking describe Subdivision position segment description
address code 6 1-6 Indicates the administrative division code of the county (city, banner, district) where the coded object's permanent residence is located when he first applies for a resident ID card. (For the codes of all regions, you can go to the website to check the latest administrative code data of counties and above) 1-2 province code
3-4 city ​​code
5-6 District code
date of birth code 8 7-14 date of birth
sequence code 3 15-17 Sequential codes for sorting people born in the same year, the same month, and the same day within the jurisdiction of the same address, and the allocation codes of the police stations under the jurisdiction of the county and district governments. The allocation codes of each police station are 10 consecutive numbers, such as "000-009" or "060-069". The last digit (the 17th digit) indicates gender, the odd number is the male distribution code, and the even number is the female distribution code. If there are more than two people in the same year, the same month and the same day, the second, third, fourth, and fifth distribution codes will be postponed.
check code 1 18 The check code (the last digit of the ID card) is a check code calculated based on the previous 17-digit code and according to the ISO7064:1983.MOD11-2 check code. In addition to the 10 Arabic numerals 0-9, there is also X, which is 10 in Roman numerals, so use X to replace the number 10

Check code calculation rules

The check code is an important basis for identifying whether an ID number actually exists. In some cases, we can judge the authenticity of an ID number through the verification code.

For the first 17 digits of the ID number, each digit i has a corresponding coefficient bi . The coefficient table is as follows:

i 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
ai 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7
bi 7 9 10 5 8 4 2 1 6 3 7 9 10 5 8 4 2

(1) The value ai in each bit i is multiplied and summed by the corresponding coefficient bi to obtain the value sum :

sum=\sum_{i=1}^{17}ai\cdot bi

(1) Divide sum by 11 to get the remainder, the result range of the remainder is [0,10], there are 11 possibilities in total, subtract the remainder from 12 to get m, the result range of m is [2,12], if m is between 2 and 10, the result is the check code (10 is represented by the Roman numeral X); if m is 11 to 12, then subtract 11, the formula is as follows :

m=12-sum%11

c=\left\{\begin{matrix} m; 2\leq m\leq 10\\ m-11;11\leq m\leq 12 \end{matrix}\right.

Note that when c=10, use X instead.

Example verification ID number 432831196411150810:

The check code is 0, and the last digit of this ID number is 0, so this is a valid ID number.

 

 

Guess you like

Origin blog.csdn.net/m0_51660523/article/details/124484168