联通物联网卡ICCID号校验位算法

Posted zhangjunwei87

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了联通物联网卡ICCID号校验位算法相关的知识,希望对你有一定的参考价值。

 

C#  算法  luhnNext(联通物联网卡ICCID号,默认最少19位,总长度20位)

public static int luhnSum(string InVal)
{
int evenSum;
int oddSum;
bool isEven;
bool IsOdd = true;
evenSum = 0;
oddSum = 0;
int strLen;
strLen = InVal.Length;
int i;
for (i = strLen; i >= 1; i--)
{
int digit;
digit = int.Parse(InVal.Substring(i - 1, 1));
if (IsOdd)
{
oddSum = oddSum + digit;
IsOdd = false;
}
else
{
digit = digit * 2;
if (digit > 9)
{
digit = digit - 9;
}
evenSum = evenSum + digit;
IsOdd = true;
}

}
int luhnSum = (oddSum + evenSum);

return luhnSum;
}

public static int luhnNext(string InVal)
{
int luhnNext;
int rst;
rst = luhnSum(InVal + 0) % 10;
if (rst == 0)
luhnNext = 0;
else
luhnNext = 10 - rst;

return luhnNext;

}

 

VB 的算法  luhnNext(联通物联网卡ICCID号,默认最少19位,总长度20位)

Function luhnSum(InVal As String) As Integer
Dim evenSum As Integer
Dim oddSum As Integer
Dim isEven As Boolean
IsOdd = True
evenSum = 0
oddSum = 0
Dim strLen As Integer
strLen = Len(InVal)
Dim i As Integer
For i = strLen To 1 Step -1
Dim digit As Integer
digit = CInt(Mid(InVal, i, 1))
If (IsOdd) Then
oddSum = oddSum + digit
IsOdd = False
Else
digit = digit * 2
If (digit > 9) Then
digit = digit - 9
End If
evenSum = evenSum + digit
IsOdd = True
End If
Next i
luhnSum = (oddSum + evenSum)
End Function

Function luhnCheck(InVal As String)
luhnCheck = (luhnSum(InVal) Mod 10) = 0
End Function

Function luhnNext(InVal As String)
Dim rst
rst = luhnSum(InVal & 0) Mod 10
If (rst = 0) Then
luhnNext = 0
Else
luhnNext = 10 - rst
End If
End Function

 












































































以上是关于联通物联网卡ICCID号校验位算法的主要内容,如果未能解决你的问题,请参考以下文章

iccid码怎么查?

物联网卡能否携号转网?

物联卡哪个平台最靠谱

一证十号禁止转售,官方推出的“物联卡安全使用规范”了解一下

物联网数据卡系统源码——通信模块

物联卡,纯流量卡,消费级物联网专用卡,这些关键词你听过吗?