18-digit ID number calculation method of the last check code

Source: Internet
Author: User

Tags: id 18-bit check code principle Java Oracle Delphi Sanoul


The citizenship number is a series of combination codes, consisting of a 17-digit ontology code and a checksum code. The order is from left to right: six digit address code, eight digit birth date code, three digit sequential code and one digit parity code.
The top six content can store the corresponding information by setting up a database, because the national administrative divisions are changing every year, and need to be updated frequently.

The final checkout code is calculated as follows:
(1) 17-digit body code weighted summation formula, first 17 digits weighted sum
S = Sum (aixwi), i = 0,1,2,..., 16
Ai: Indicates the ID number value of position I
Wi: Represents the weighting factor in position I, Wi:7 9 10 5 8 4 2 1 6 3 7 9 10 5 8 4 2

(2) Computational model
Y = mod (S, 11)
Y is the remainder of s divided by 11, mathematically referred to as modulo.

(3) The corresponding check code is obtained through the model
Y:0 1 2 3 4 5 6 7 8 9 10

Check code: 1 0 X 9 8 7 6 5 4 3 2

Java:

public static char doverify (String id_no);
{
Char Pszsrc[]=id_no.tochararray ();
int is = 0;
int iw[]={7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2};
Char szvercode[] = new char[]{' 1 ', ' 0 ', ' X ', ' 9 ', ' 8 ', ' 7 ', ' 6 ', ' 5 ', ' 4 ', ' 3 ', ' 2 '};
int i;
for (i=0;i<17;i++);
{
is + = (int);(p szsrc[i]-' 0 '); * Iw[i];
}
int IY = is%11;
return Szvercode[iy];
}

Oracle:

Create or Replace function identity_card18 (id_no char) return Char
Result Char (18);
Type Myarray1 is table of number index by Binary_integer;
Type Myarray2 is table of char index by Binary_integer;
Ax Myarray1;
Bx Myarray2;
I number (3);
A number (12,0);
Begin
Ax (1): = 7;
Ax (2): = 9;
Ax (3): = 10;
Ax (4): = 5;
Ax (5): = 8;
Ax (6): = 4;
Ax (7): = 2;
Ax (8): = 1;
Ax (9): = 6;
Ax (10): = 3;
Ax (11): = 7;
Ax (12): = 9;
Ax (13): = 10;
Ax (14): = 5;
Ax (15): = 8;
Ax (16): = 4;
Ax (17): = 2;
Bx (1): = ' 1 ';
Bx (2): = ' 0 ';
Bx (3): = ' X ';
Bx (4): = ' 9 ';
Bx (5): = ' 8 ';
Bx (6): = ' 7 ';
Bx (7): = ' 6 ';
Bx (8): = ' 5 ';
Bx (9): = ' 4 ';
Bx (10): = ' 3 ';
Bx (11): = ' 2 ';

Result: = Trim (Substr (Trim (id_no), 1,17));

If Length (Trim (Result) = Then
Result: = substr (result,1,6) | | ' 19 ' | | SUBSTR (result,7,9);
End If;

If Length (Trim (Result) = Then
A: = 0;
For I in 1..ax.count loop
A: = a + Ax (i) * To_number (SUBSTR (result,i,1));
End Loop;
A: = a mod 11;
Result: = Trim (result) | | Bx (a+1);

Else

Result: = ' 000000000000000000 ';
End If;

return (result);
End Identity_card18;

Delphi:

function Identity_card18 (id_no:string): String;
Const
AX:ARRAY[0..16] of the Integer = (7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2);
BX:ARRAY[0..10] of String = (' 1 ', ' 0 ', ' X ', ' 9 ', ' 8 ', ' 7 ', ' 6 ', ' 5 ', ' 4 ', ' 3 ', ' 2 ');
Var
I,a:integer;
s:string;
Begin
S: = Trim (Id_no);
A: = 0;

If Length (Trim (S)) = Then
S: = Copy (Trim (s), 1,6) + ' + ' + Copy (trim (s), 7,9);

If Length (Trim (S)) = Then
Begin
For I: = 0 Todo
A: = a + ax[i] * Strtoint (s[i+1]);
S: = Trim (s) + bx[a mod 11];
End Else
S: = ' 000000000000000000 ';

Result: = S;
End

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.