2 * Output a base64 string.
5 * - Character 62 and 63;
6 * - To pad or not to pad.
12 size_t genbase64(char *output, const void *input, size_t size, int flags)
15 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+_";
23 charz[62] = (char)flags;
24 charz[63] = (char)(flags >> 8);
26 p = input; q = output;
31 buf[1] = (left > 1) ? p[1] : 0;
36 bv = (p[0] << 16) | (p[1] << 8) | p[2];
40 for ( j = 0 ; j < 4 ; j++ ) {
41 *q++ = charz[(bv >> 18) & 0x3f];
48 if (flags & BASE64_PAD)
55 if (flags & BASE64_PAD)
75 int main(int argc, char *argv[])
81 for (i = 1; i < argc; i++) {
82 printf("Original: \"%s\"\n", argv[i]);
84 len = strlen(argv[i]);
85 bytes = genbase64(buf, argv[i], len, BASE64_MIME|BASE64_PAD);
86 printf(" MIME: \"%s\" (%d)\n", buf, bytes);
87 bytes = genbase64(buf, argv[i], len, BASE64_SAFE);
88 printf(" Safe: \"%s\" (%d)\n", buf, bytes);