Now the new ID card has risen from 15 points to 18, many software may use the input of the ID card, the test work, and the code of the new ID card seems to have few articles, I found it in 2000. An article in the computer world, found that the current ID card check code may be an English letter X (in fact this X is a Roman letter, indicating 10 meaning), why use letters? who knows? The number key at which the phone is at least will not enter the new number. (The current method is to use * alternative, good in the # * 2 keys, I also did CTI, huh, huh, then I wrote a Delphi process, I posted "Netease", but not for 100 years old The old man above.
I found that there are a lot of netizens asking this question, so I have sorted out the re-posted, the new bottle is old wine.
According to the provisions of the citizen identity number in the National Standard GB 11643-1999 in the People's Republic of China, the citizen identity number is the characteristic group code, consists of the seventeenth digital body code and a digital check code. Arrange the order from left to right as: six digit address code, eight digit born date code, three digital sequence code and one digital check code.
The address code represents the administrative region of the county (city, flag, district) in the county (city, flag, district) of the coding object. The birthday period indicates the year, month, day of the birthday, month, and the year, the year, the year, month, and day without separator. The sequence code indicates the sequence number of the person born in the same year, month, and day. The odd number of sequence codes is given to men, even giving women. The check code is based on the seventeenth digit of the previous seventeen digits, calculated by the ISO 7064: 1983.MOD 11-2 check code. The calculation method will be described below.
15 identity card coding first expanded the birth year to 4 digits, simple is to increase a 19, but this is not used for people born in 1900 (such birthday is not much)
A male citizenship number is 34052419800101001, first, according to formula (1):
Σ (AI × Wi) (MOD 11) ........................................ (1)
Equation (1): i ---- Indicates the number character from the zip number, including the calibration code; AI ---- represents the number character value at the first position; Wi ---- show The weighting factor at the i position 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 0 1 A1
Wi 7 9 10 5 8 4 2 1 6 3 7 9 10 5 8 4 2 1
Ai × Wi 21 36 0 25 16 16 2 9 48 0 0 9 0 5 0 0 2 A1
Calculated according to equation (1):
Σ (AI × Wi) = (21 36 0 25 16 16 2 9 48 5 0 0 2) = 189
189 ÷ 11 = 17 2/11
Σ (AI × Wi) (MOD 11) = 2
The corresponding check code is then isolated from the following table according to the calculated result, where x represents the calculation result 10:
Σ (AI × Wi) (MOD 11) 0 1 2 3 4 5 6 7 8 9 10 Check code character value AI 1 0 x 9 8 7 6 5 4 3 2 According to the top table, the calculation result is 2 schools The code for the citizenship number of the person should be 34052419800101001x. Here is my Delphi function
Function IDFun (ID: String): String; const w: array [1..18] of integer = (7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2, 1); A: Array [0..10] of char = ('1', '0', 'x', '9', '8', '7', '6 ',' 5 ',' 4 ',' 3 ',' 2 '); VAR I, J, S: Integer; Newid: String; Begin If Length (ID) <> 15 Then Res: =' Else Begin NewID : = ID; INSERT ('19 ', newid, 7); s: = 0; try for i: = 1 to 17 do begin j: = start (newID [i]) * w [i]; s: = s J; End; Except results: = '; exit; end; s: = s mod 11; result: = newid a [s]; end;
I have implemented this algorithm with PHP, C and JavaScript, with the website and other programs. I always think that it is much better to give the algorithm than to the source code. I have the above algorithm explanation. I believe this code is not difficult to become other languages.
If you have any questions, please give me mail: pazee@21cn.com