Base64 Encoding/Decoding Implementation....

S

Sridhar Anupindi

Hi,

I am using the following algorithm to decode the string into ASCII
set of characters.. The function returns me the decoded string but the
problem is that my string contains both normal characters and also the
BASE64 Character set ( like this
"<searchKeyword>çãñ</searchKeyword>").
Since I am passing the entire string to this function and I want this
function to handle only the BASE64 Characters and ignore the rest of
the characters. Any help is greatly appreciated.

string decode(const string& data)
{
string::size_type i;
char c;
char c1;
string::size_type len = data.length();
string ret;

ret.reserve(len);

for (i = 0; i < len; ++i)
{

c = (char) DecodeTable[(unsigned char)data];
++i;
c1 = (char) DecodeTable[(unsigned char)data];
c = (c << 2) | ((c1 >> 4) & 0x3);
ret.append(1, c);
if (++i < len)
{
c = data;
if (fillchar == c)
break;

c = (char) DecodeTable[(unsigned char)data];
c1 = ((c1 << 4) & 0xf0) | ((c >> 2) & 0xf);
ret.append(1, c1);
}

if (++i < len)
{
c1 = data;
if (fillchar == c1)
break;

c1 = (char) DecodeTable[(unsigned char)data];
c = ((c << 6) & 0xc0) | c1;
ret.append(1, c);
}
}

return(ret);
}

Thanks

Sridhar Anupindi
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top