#include #include char cb64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; /* lookup table */ /** * Encodes three input chars into four output chars based on the base64 scheme. * @param in chararray with input characters * @param out chararray where the output is written to * @param len number of chars to be used from input */ void encode_block( unsigned char in[3], unsigned char out[4], int len ) { out[0] = cb64[ in[0] >> 2 ]; out[1] = cb64[ ((in[0] & 0x03) << 4) | (len > 1 ? (( in[1] & 0xf0) >> 4) : 0)]; out[2] = (unsigned char) (len > 1 ? cb64[((in[1] & 0x0f) << 2) | (len > 2 ? ((in[2] & 0xc0) >> 6) : 0)] : '='); out[3] = (unsigned char) (len > 2 ? cb64[in[2] & 0x3f] : '='); } /** * Encodes the input string into an output string based on the base64 scheme. * @param length size of input string * @param input string with input characters * @param output string where the output is written to. It has to be long enough to hold the output */ void encode(int length, char *input, char *output) { unsigned char in[3], out[4]; int iterator = 0; int blocksize = 3; for(iterator = 0; iterator <= (length / 3); ++iterator ) { if (iterator == (length / 3)) { blocksize = length % 3; } int i; for (i=0; i