ID card number coding rules and verification

https://www.jianshu.com/p/ead5b08e9839

Preface

According to Article 23 of the newly revised "Resident ID Card Law of the People's Republic of China", the resident ID card obtained in accordance with the "Regulations of the People's Republic of China Resident ID Card" will cease to be used from January 1, 2013. That is, the first-generation ID card has ceased to be used on January 1, 2013. The content of this article applies to the second-generation ID card. Unless otherwise specified, the ID cards mentioned in this article refer to the second-generation ID card.

The jdk version I currently use is 1.6.0_29, the Eclipse version is Juno Release, Build id 20120614-1722. Unless otherwise specified, all Java codes in this article are based on this.

This article contains a large number of mathematical formulas and Java codes. The mobile phone has a poor browsing experience. You can browse textual content on the mobile phone. Math formulas and Java codes can be browsed on the PC. At the same time, it is recommended to prepare paper and pen for the calculation of mathematical formulas. Readers with a certain mathematical foundation can also ignore this suggestion.

The Java code provided in this article is written by the author line by line, repeated consideration, in order to be able to offer a good idea, so that beginners can work tirelessly, to a higher level on the road of learning Java. The content and deficiencies of this article are welcome to criticize and correct.

Revision record

version number Revision date Revision description
V0.1 2018/08/13 First draft
V1.0 2018/09/02 release

Reference

  1. The Resident Identity Card Law of the People's Republic of China
  2. National Standard of the People's Republic of China GB/T 2260-2007 Code of Administrative Division of the People's Republic of China
  3. National Standard of the People's Republic of China GB 11643-1999 Citizen ID Number
  4. National Standard of the People's Republic of China GB/T 17710-1999 Data Processing Check Code System
  5. National Standard of the People's Republic of China GB/T 17710-2008 Information Technology Security Technology Check Character System
  6. ISO 7064:1983 Data processing - Check character systems
  7. ISO/IEC 7064:2003 Information technology - Security techniques - Check character systems

Coding rules for ID number

The ID number has a total of 18 digits, consisting of 17 body codes and 1 check code.

  1. The first 6 digits are the address code, which represents the administrative division code of the place where the account is registered, and is implemented in accordance with the national standard of "Administrative Division Code of the People's Republic of China" (GB/T2260);
  2. 7 to 14 digits are the date of birth, in YYYYMMDD format;
  3. Digits 15 to 17 are sequence codes, which indicate the sequence numbers for people born in the same year, the same month, and the same day within the area identified by the same address code. The odd numbers of the sequence codes are assigned to males, and the even numbers are assigned to females, that is, the 17th Odd number means male, even number means female;
  4. The 18th digit is the check code, which adopts the ISO 7064:1983, MOD 11-2 check character system. The calculation rules are described in the next chapter.

The difference between the first-generation ID card and the second-generation ID card is:

  1. The first-generation ID card has 15 digits, and the second-generation ID card has 18 digits;
  2. The first-generation ID card uses the YYMMDD format for the date of birth, and the second-generation ID card uses the YYYYMMDD format for the date of birth;
  3. The first-generation ID card has no check code, and the second-generation ID card has a check code.

Verification process:

D = D_nD_n_-_1...D_2D_1, ( n = 18)

T_m = \sum_{i =1}^{m} = D_i * 2^i ;

S_m = T_n - T_m;

1 = S_nmod(11)=(S_n_-_1+D_1)mod(11)

D_1 = (1-S_n_-_1)mod(11)

\begin{pmatrix} 0&1&2& 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & \\ 1 & 0 & x & 9 & 8 & 7 & 6 & 5 & 4& 3 & 2 & \end{pmatrix}

 Where x represents the Roman numeral 10

Basic characters

I

V

X

L

C

D

M

The corresponding Arabic numerals are expressed as

1

5

10

50

100

500

1000

Guess you like

Origin blog.csdn.net/beebeeyoung/article/details/107375296