ID card verification code generation algorithm

Source: Internet
Author: User

This section describes how to calculate the last verification code of an 18-digit ID card number.

A citizenship number is a combination of features and consists of a 17-digit ontology code and a verification code. The six-digit address code, eight-digit birth date code, three-digit sequence code, and one-digit verification code are arranged from left to right.

Verification Method:
(1) 17-digit ontology weighted sum formula
S = sum (ai * WI), I = 0,..., 16, first sum the right of the first 17 digits
AI: indicates the number of ID card numbers at location I.
Wi: indicates the weighting factor at position I.
Wi: 7 9 10 5 8 4 2 1 6 3 7 9 10 5 8 4 2

(2) Computing Model
Y = Mod (S, 11)

(3) obtain the corresponding verification code through the modulo
Y: 0 1 2 3 4 5 6 7 8 9 10
Verification Code: 1 0x9 8 7 6 5 4 3 2

Below is CProgramCode:
// Char szsrc1 [] = "11010519491231002x ";
// Doverify (szsrc1 );
// Charszsrc2 [] = "440524188001010014 ";
// Doverify (szsrc2 );

Char doverify (const char * pszsrc)
{
Int Is = 0;
Int IW [] = {7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2 };
Static char szvercode [] = "10x98765432 ";
Int I;
For (I = 0; I <17; I ++)
{
Is + = (INT) (pszsrc [I]-'0') * IW [I];
}
Int Iy = is % 11;
// Printf ("% d % 11 = Iy = % d/N", is, Iy );
// Printf ("% C/N", szvercode [Iy]);
Return szvercode [Iy];

}

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.