36 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
37 int bit_offset, byte_offset, idx, i, n;
38 unsigned char *d = (
unsigned char *)s;
43 while (*s && (p = strchr(b64, *s))) {
45 byte_offset = (i * 6) / 8;
46 bit_offset = (i * 6) % 8;
47 d[byte_offset] &= ~((1 << (8 - bit_offset)) - 1);
49 d[byte_offset] |= (idx << (2 - bit_offset));
52 d[byte_offset] |= (idx >> (bit_offset - 2));
53 d[byte_offset + 1] = 0;
54 d[byte_offset + 1] |= (idx << (8 - (bit_offset - 2))) & 0xFF;
65 void rs_base64(
unsigned char const *buf,
int n,
char *out)
68 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
72 bytes = ((n * 8) + 5) / 6;
74 for (i = 0; i < bytes; i++) {
75 int byte = (i * 6) / 8;
76 int bit = (i * 6) % 8;
81 *out = b64[(buf[byte] >> (2 - bit)) & 0x3F];
84 *out = b64[(buf[byte] << (bit - 2)) & 0x3F];
87 b64[(buf[byte] << (bit - 2) | buf[
byte + 1] >> (10 - bit)) &