|
发表于 2006-1-7 19:44:00
|
显示全部楼层
<P>德信的算法:</P><P>AnsiString GetIMEIStrWithCD(AnsiString sinput)
{
vError = ERR_SUCCESS;
AnsiString sIMEI = "";
try
{
AnsiString imei = AnsiString(sinput);
if(imei != "")
{
if(imei.Length() >= 14)
{
imei = imei.SubString(1,14);
if(IsDec(imei))
{
u8 buf[15];
u8 CD;
memset(buf,0,15);
AnsiString sV;
for(int i =0;i<14;i++)
{
sV = imei.SubString(i+1,1);
buf = sV.ToInt() & 0xff;
}
CD = 0;
for(int i =0;i<14;i++)
{
if(i%2 == 1)
{
sV = IntToStr(buf * 2);
if(sV.Length() == 1)
CD += buf * 2;
else
CD += AnsiString(sV.SubString(1,1)).ToInt() + AnsiString(sV.SubString(2,1)).ToInt();
}
else
CD += buf;
}
if((CD%10) != 0)
CD = 10 - CD%10;
else
CD = 0;
imei += IntToStr(CD);
sIMEI = imei.SubString(1,15);
}
else
vError = ERR_INVALID_IMEI;
}
else
vError = ERR_POINTER_LENGTH;
}
else
vError = ERR_NULL_STRING;
}
catch(...)
{
sIMEI = "";
vError = ERR_ABNORMAL;
}
return sIMEI;
}</P>[br]<p align=right><font color=red>+3 RD币</font></p> |
|