char* table = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
DWORD GetIndex(char ch)
{
int nSize = strlen(table);
for(int i = 0; i < nSize; i++)
{
if(ch == table[i])
{
return i;
}
}
return -1;
}
void decode(char* pwd, char *pOut)
{
DWORD dwSize = strlen(pwd);
for(int i = 0, j = 0; i < dwSize; i += 4, j += 3)
{
char ch1 = GetIndex(pwd[i]);
char ch2 = GetIndex(pwd[i + 1]);
char ch3 = GetIndex(pwd[i + 2]);
char ch4 = GetIndex(pwd[i + 3]);
DWORD dwVal = ((ch1 << 6 | ch2) << 6 | ch3) << 6 | ch4;
pOut[j + 2] = dwVal & 0xFF;
pOut[j + 1] = dwVal >> 8 & 0xFF;
pOut[j] = dwVal >> 16 & 0xFF;
}
}