ID Card Algorithm

Source: Internet
Author: User
*
According to the provisions on citizenship numbers in the National Standard GB 11643-1999 of the People's Republic of China, citizenship numbers are feature groups
Consists of a 17-digit ontology code and a digital verification code. The order is from left to right: six digits address code, eight digits
Birth date code, three digit sequence code, and one digit verification code.
The address code indicates the Administrative Code of the county (city, flag, district) where the resident account of the encoding object is located. The birthdate code indicates the year and month when the encoding object is born.
, Day, in which the year is represented by four digits, and there is no separator between the year, month, and day. The sequence code indicates the range of regions identified by the same address code.
The sequence number of the person born in the same year, month, or day. The odd number of the sequence code is assigned to men, and the even number is assigned to women. The Verification Code is based on the previous
The 17-digit verification code is calculated according to the ISO 7064: 1983.mod 11-2 verification code. The following is an example of this calculation method.
The 15-digit ID code first expands the birth year to four digits. Simply, it adds 19 digits, but this is not used for persons born in 1900.
(There are not many such stars)
The subject code of a male citizenship number is 34052419800101001. First, calculated according to formula (1:
SIGMA (AI x WI) (mod 11 ).......................................... (1)
Formula (1:
I ---- indicates the serial number of the character from the start to the left, including the verification code;
AI ---- indicates the number character value at position I;
Wi ---- indicates the weighting factor at position I. The value is calculated based on the formula Wi = 2 (n-1) (mod 11.
I 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1
AI 3 4 0 5 2 4 1 9 8 0 0 1 0 1 0 1 A1
Wi 7 9 10 5 8 4 2 1 6 3 7 9 10 5 8 4 2 1
AI x wi 21 36 0 25 16 16 2 9 48 0 9 0 5 0 0 2 A1
Calculate according to formula (1:
SIGMA (AI x WI) = (21 + 36 + 0 + 25 + 16 + 16 + 2 + 9 + 48 + 0 + 0 + 9 + 0 + 5 + 0 + 0 + 2) = 189
189 usd11 = 17 + 2/11
SIGMA (AI x WI) (mod 11) = 2
Then, based on the calculation result, find the corresponding verification code from the following table, where X indicates that the calculation result is 10:
SIGMA (AI x WI) (mod 11) 0 1 2 3 4 5 6 7 8 9 10
Verification Code character value: AI 1 0x9 8 7 6 5 4 3 2
According to the preceding table, the verification code of the calculation result 2 is found to be 34052419800101001x.
*/
/**
* ID card number escalation
* @ Param _ 15 idnum 15-digit ID card number
* @ Return 18-digit ID card number
* @ Author apan
*/
Public static string idnum15to18 (string _ 15 idnum ){
String _ 18 idnum = ""; // The 18-digit ID card number after the upgrade
_ 15 idnum = _ 15idnum. Trim (); // 15-digit number except Space
Int sum = 0;
Int J = 0;
Int [] W = {,}; // Weighting Factor
String [] A = {"1", "0", "X", "9", "8", "7", "6", "5 ", "4", "3", "2"}; // Verification Code
If (_ 15idnum. Length ()! = 15 ){
Return _ 15 idnum; // If the ID card number is not 15 characters, the original value is returned.
} Else {
// Supplement year 80 --> 1980
_ 18 idnum = _ 15idnum. substring (0, 6) + "19" + _ 15idnum. substring (6 );
}
// Sum
For (INT I = 0; I <17; I ++ ){
J = W * Integer. parseint (_ 18idnum. substring (I, I + 1 ));
Sum = sum + J;
}
// Obtain the remainder
Sum = sum % 11;
// Add Verification Code
_ 18 idnum = _ 18 idnum + A [Sum];
// Return the 18-digit ID card number
Return _ 18 idnum;

"Re: ID card number escalation algorithm and JAVA Implementation (Note: no verification )"

Note:
SIGMA (AI x WI) (mod 11)
The true meaning is:
(SIGMA (AI x WI) mod 11

Wi = 2 (n-1) (mod 11)
The true meaning is
(N-1) power of 2 and mod 11 again

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.