原15位到18位,如410926640827002->410926196408270028加入出生的世紀代號(第13、14位)及驗證碼(第18位)。
前六位爲出生地。中間8爲出生年月,其次爲性別碼男奇女偶,後兩位是順序碼。最後爲校驗碼。
下面細解校驗碼:
1. 對前17位數字本體碼加權求和 2-18
公式爲:S = Sum(Ai * Wi), i 前17位
其中ai表示第i位置上的身份證號碼數字值,Wi表示第i位置上的加權因子
wi有個對應的固定表:
0 1 2 3 4 5 6 7 8 9 10
1 0 X 9 8 7 6 5 4 3 2
i 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1
ai 4 1 0 9 2 6 1 9 6 4 0 8 2 7 0 0 2
wi 7 9 10 5 8 4 2 1 6 3 7 9 10 5 8 4 2
ai×wi 28 9 0 45 16 24 2 9 36 12 0 72 20 35 0 04各項相加=z
Z=312mod 11=4查表,得8:
0 1 2 3 4 5 6 7 8 9 10
1 0 X 9 8 7 6 5 4 3 2
因此410926196408270028
算法:
function ID15T18(strTemp)
{
array aInt = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2);
array aCh = new Array(’1’, ’0’, ’X’, ’9’, ’8’, ’7’, ’6’, ’5’, ’4’, ’3’, ’2’);
array nTemp = 0, i;
if(strTemp.length==15)
{
strTemp = strTemp.substr(0,6) + ’19’ + strTemp.substr(6,strTemp.length-6);
for(i = 0; i 〈 strTemp.length; i ++)
{
nTemp += strTemp.substr(i, i+1) * aInt[i];
}
strTemp += aCh[nTemp % 11];
}
return strTemp;
}