VB.NET实现身份证15位升18位的算法

    技术2022-05-11  11

    <script type="text/javascript"> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script> <script type="text/javascript"> </script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>

        根据〖中华人民共和国国家标准 GB 11643-1999〗中有关公民身份号码的规定,公民身份号码是特征组合码,由十七位数字本体码和一位数字校验码组成。排列顺序从左至右依次为:六位数字地址码,八位数字出生日期码,三位数字顺序码和一位数字校验码。

        地址码表示编码对象常住户口所在县(市、旗、区)的行政区划代码。生日期码表示编码对象出生的年、月、日,其中年份用四位数字表示,年、月、日之间不用分隔符。顺序码表示同一地址码所标识的区域范围内,对同年、月、日出生的人员编定的顺序号。顺序码的奇数分给男性,偶数分给女性。校验码是根据前面十七位数字码,按照ISO 7064:1983.MOD 11-2校验码计算出来的检验码。下面举例说明该计算方法。 

        15位的身份证编码首先把出生年扩展为4位,简单的就是增加一个19,但是这对于1900年出生的人不使用(这样的寿星不多了)

        某男性公民身份号码本体码为34052419800101001,首先按照公式⑴计算:

    ∑(ai×Wi)(mod 11)……………………………………(1)

    公式(1)中:i----表示号码字符从由至左包括校验码在内的位置序号;ai----表示第i位置上的号码字符值;Wi----示第i位置上的加权因子,其数值依据公式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

    根据公式(1)进行计算:

    ∑(ai×Wi) =(21+36+0+25+16+16+2+9+48++0+0+9+0+5+0+0+2) = 189

    189 ÷ 11 = 17 + 2/11

    ∑(ai×Wi)(mod 11) = 2

        然后根据计算的结果,从下面的表中查出相应的校验码,其中X表示计算结果为10:

    ∑(ai×WI)(mod 11)   0 1 2 3 4 5 6 7 8 9 10 校验码字符值ai       1 0 X 9 8 7 6 5 4 3  2    根据上表,查出计算结果为2的校验码为所以该人员的公民身份号码应该为 34052419800101001X。

        '功能:将15的身份证号升为18位(根据GB 11643-1999)    '参数:原来的号码    '返回:升位后的18位号码    Private Function getCheckCode(ByVal SFZH As String) As String        Dim strJiaoYan() As Char = {"1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2"}        Dim intQuan() As Integer = {7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2, 1}        Dim strTemp As String        Dim intTemp As String        Dim i As Integer

            strTemp = SFZH.Substring(0, 6) & "19" & SFZH.Substring(6)        For i = 0 To strTemp.Length - 1            intTemp = intTemp + Convert.ToInt32(strTemp.Substring(i, 1)) * intQuan(i)        Next        intTemp = intTemp Mod 11

            Return strTemp & strJiaoYan(intTemp)    End Function

     

    <script type="text/javascript"> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script> <script type="text/javascript"> </script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>

    最新回复(0)