Code: Select all
string UTILS_base64_encode(const string src)
{
string basis_64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
int a, b, c, d;
int position, padding, length, buffer;
string output="";
padding = strlen(src) % 3;
position = -1;
// Make sure any padding is handled outside of the loop.
length = strlen(src) - padding;
while (++position < length) {
// Read three bytes, i.e. 24 bits.
a = src[position] 18 & 0x3F)] + "" +
basis_64[(buffer >> 12 & 0x3F)] + "" +
basis_64[(buffer >> 6 & 0x3F)] + "" +
basis_64[(buffer & 0x3F)]
);
}
if (padding == 2) {
a = src[position] > 10)] + "" +
basis_64[((buffer >> 4) & 0x3F)] + "" +
basis_64[((buffer > 2)] + "" + basis_64[((buffer > (-2 * bitCounter & 6);
output += c;
}
}
return output;
}