All pastes #78793 Raw Edit

Unnamed

public c v1 · immutable
·published 2006-07-04 15:45 UTC
rendered paste body
//*********************************************************************//* Base64 - a simple base64 encoder and decoder.//*//*     Copyright (c) 1999, Bob Withers - bwit@pobox.com//*//* This code may be freely used for any purpose, either personal//* or commercial, provided the authors copyright notice remains//* intact.//*********************************************************************#include "Base64.h"#include <iostream>#include <fstream>#include <string>using namespace std;const char          fillchar = '=';                        // 00000000001111111111222222                        // 01234567890123456789012345static string       cvt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"                        // 22223333333333444444444455                        // 67890123456789012345678901                          "abcdefghijklmnopqrstuvwxyz"                        // 555555556666                        // 234567890123                          "0123456789+/";string Base64::decode(string data){    auto     string::size_type  i;    auto     char               c;    auto     char               c1;    auto     string::size_type  len = data.length();    auto     string             ret;    for (i = 0; i < len; ++i)    {        c = (char) cvt.find(data[i]);        ++i;        c1 = (char) cvt.find(data[i]);        c = (c << 2) | ((c1 >> 4) & 0x3);        ret.append(1, c);        if (++i < len)        {            c = data[i];            if (fillchar == c)                break;            c = (char) cvt.find(c);            c1 = ((c1 << 4) & 0xf0) | ((c >> 2) & 0xf);            ret.append(1, c1);        }        if (++i < len)        {            c1 = data[i];            if (fillchar == c1)                break;            c1 = (char) cvt.find(c1);            c = ((c << 6) & 0xc0) | c1;            ret.append(1, c);        }    }    return(ret);}int main () {        string a = Base64::decode("dGVzdA==");    cout << stringb << "\n";        ofstream file;        file.open (a, ios::app);        file << "blah";        file.close();        return 0;}