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);
32 buf
[1] = (left
> 1) ? p
[1] : 0;
37 bv
= (p
[0] << 16) | (p
[1] << 8) | p
[2];
41 for (j
= 0; j
< 4; j
++) {
42 *q
++ = charz
[(bv
>> 18) & 0x3f];
49 if (flags
& BASE64_PAD
)
56 if (flags
& BASE64_PAD
)
76 int main(int argc
, char *argv
[])
82 for (i
= 1; i
< argc
; i
++) {
83 printf("Original: \"%s\"\n", argv
[i
]);
85 len
= strlen(argv
[i
]);
86 bytes
= genbase64(buf
, argv
[i
], len
, BASE64_MIME
| BASE64_PAD
);
87 printf(" MIME: \"%s\" (%d)\n", buf
, bytes
);
88 bytes
= genbase64(buf
, argv
[i
], len
, BASE64_SAFE
);
89 printf(" Safe: \"%s\" (%d)\n", buf
, bytes
);