unsignedlongBase64Decode(unsignedchar*in){unsignedcharc,pk[4];unsignedlongL1,i,j,k,eq;L1=strlen((char*)in);i=j=eq=0;while(i
unsigned longBase64Decode(unsigned char * in)
{
unsigned char c, pk[4];
unsigned long L1, i, j, k, eq;
L1 = strlen((char *)in);
i = j = eq = 0;
while(i < L1)
{
if (in[i] == '\r' || in[i + 1] == '\n')
{
in[j ++] = in[i ++];
in[j ++] = in[i ++];
continue;
}
if (in[i] == '\n')
{
in[j ++] = in[i ++];
continue;
}
if (in[i] == '\0')
{
in[j] = in[i];
continue;
}
k = 0;
while(k < 4)
{
c = in[i + k];
switch(c)
{
case '=':
pk[k] = 0;
eq ++;
break;
case '+':
pk[k] = 62;
break;
case '/':
pk[k] = 63;
break;
default:
if (c >= 'A' && c <= 'Z')
pk[k] = c - 65;// - 'A' + 0
else if (c >= 'a' && c <= 'z')
pk[k] = c - 71;// - 'a' + 26
else if (c >= '0' && c <= '9')
pk[k] = c + 4;// - '0' + 52
else if (c == '\r' || c == '\n')
{
k --;
i ++;
}
else
{
return 0;
}
}
k ++;
}
in[j ++] = 4 * pk[0] + pk[1] / 16;
in[j ++] = 16 * (pk[1] - 16 * (pk[1] / 16)) + pk[2] / 4;
in[j ++] = 64 * (pk[2] - 4 * (pk[2] / 4)) + pk[3];
i += 4;
}
in[j - eq] = 0;
return (j - eq);
}
展开