相關鏈接:
Public Shared Function per15To18(ByVal perIDSrc As String) As String
Dim [iS] As Integer = 0
''加權因子常數
Dim iW As Integer() = New Integer() {7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2}
''校驗碼常數
Dim LastCode As String = "10X98765432"
''新SFZ號
Dim perIDNew As String
perIDNew = perIDSrc.Substring(0, 6)
perIDNew += "19"
perIDNew += perIDSrc.Substring(6, 9)
For i As Integer = 0 To 16
''進行加權求和
[iS] += Integer.Parse(perIDNew.Substring(i, 1)) * iW(i)
Next
''取模運算,得到模值
Dim iY As Integer = [iS] Mod 11
''從LastCode中取得以模為索引號的值,加到SFZ的最後一位,即為新SFZ號。
perIDNew += LastCode.Substring(iY, 1)
Return perIDNew
End Function
public static string per15To18(string perIDSrc)
{
int iS = 0;
//加權因子常數
int[] iW=new int[]{7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2};
//校驗碼常數 string LastCode="10X98765432";
//新SFZ號
string perIDNew;
perIDNew=perIDSrc.Substring(0,6);
perIDNew += "19";
perIDNew += perIDSrc.Substring(6,9);
//進行加權求和
for( int i=0; i<17; i++)
{
iS += int.Parse(perIDNew.Substring(i,1)) * iW[i];
}
//取模運算,得到模值
int iY = iS%11;
//從LastCode中取得以模為索引號的值,加到SFZ的最後一位,即為新SFZ號。
perIDNew += LastCode.Substring(iY,1);
return perIDNew;
}