Code:
static char * _cpBase64Encoding = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
void Base64EncodeFunc( char* cpInput, char* cpOutput )
{
int nIdx[ 4 ];
while ( '\0' != *cpInput )
{
nIdx[0] = ((*cpInput) & 0xFC)>>2;
nIdx[1] = ((*cpInput) & 0x03)<<4;
cpInput++;
if ( '\0' != *cpInput )
{
nIdx[1] |= ((*cpInput) & 0xF0)>>4;
nIdx[2] = ((*cpInput) & 0x0F)<<2;
cpInput++;
if ( '\0' != (*cpInput) )
{
nIdx[2] |= ((*cpInput) & 0xC0) >> 6;
nIdx[3] = (*cpInput) & 0x3F;
cpInput++;
}
else
nIdx[3] = 64;
}
else
{
nIdx[2] = 64;
nIdx[3] = 64;
}
*(cpOutput+0) = *(_cpBase64Encoding + nIdx[0]);
*(cpOutput+1) = *(_cpBase64Encoding + nIdx[1]);
*(cpOutput+2) = *(_cpBase64Encoding + nIdx[2]);
*(cpOutput+3) = *(_cpBase64Encoding + nIdx[3]);
cpOutput += 4;
}
*cpOutput = '\0';
return;
}