By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,413 Members | 996 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,413 IT Pros & Developers. It's quick & easy.

Base64 Encoding/Decoding Implementation....

P: n/a
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>&#xc3;&#xa7;&#xc3;&#xa3;&#xc3;&#xb 1;</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]];
++i;
c1 = (char) DecodeTable[(unsigned char)data[i]];
c = (c << 2) | ((c1 >> 4) & 0x3);
ret.append(1, c);
if (++i < len)
{
c = data[i];
if (fillchar == c)
break;

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

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

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

return(ret);
}

Thanks

Sridhar Anupindi
Jul 22 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.