Base64 Encoding/Decoding Implementation....

Discussion in 'C++' started by Sridhar Anupindi, May 25, 2004.

  1. 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
     
    Sridhar Anupindi, May 25, 2004
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Base64 decoding

    , Jan 24, 2006, in forum: XML
    Replies:
    0
    Views:
    460
  2. Kuldeep

    Base64 Decoding

    Kuldeep, Aug 30, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    621
    =?Utf-8?B?SGFyZHkgV2FuZw==?=
    Oct 3, 2006
  3. BB

    Decoding Base64

    BB, Jul 28, 2006, in forum: C Programming
    Replies:
    14
    Views:
    654
    Becca
    Jul 29, 2006
  4. ashu
    Replies:
    2
    Views:
    713
  5. Iñaki Baz Castillo
    Replies:
    7
    Views:
    653
    Rick DeNatale
    Dec 3, 2009
Loading...

Share This Page