43 typedef unsigned char BYTE;
48 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
49 "abcdefghijklmnopqrstuvwxyz"
53 return (isalnum(c) || (c ==
'+') || (c ==
'/'));
56 string inline encode(
BYTE const* buf,
unsigned int bufLen) {
66 char_array_3[i++] = *(buf++);
68 char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
69 char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
70 char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
71 char_array_4[3] = char_array_3[2] & 0x3f;
73 for (i = 0; (i < 4) ; i++)
81 for (j = i; j < 3; j++)
82 char_array_3[j] =
'\0';
84 char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
85 char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
86 char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
87 char_array_4[3] = char_array_3[2] & 0x3f;
89 for (j = 0; (j < i + 1); j++)
100 vector<BYTE>
inline decode(
string const& encoded_string) {
101 size_t in_len = encoded_string.size();
105 BYTE char_array_4[4], char_array_3[3];
108 while (in_len-- && ( encoded_string[in_] !=
'=') &&
is_base64(encoded_string[in_])) {
109 char_array_4[i++] = encoded_string[in_];
112 for (i = 0; i < 4; i++)
115 char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4);
116 char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
117 char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3];
119 for (i = 0; (i < 3); i++)
120 ret.push_back(char_array_3[i]);
126 for (
int j = i; j < 4; j++)
129 for (
int j = 0; j < 4; j++)
132 char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4);
133 char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
134 char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3];
136 for (
int j = 0; (j < i - 1); j++)
137 ret.push_back(char_array_3[j]);
bool is_base64(BYTE c)
Definition: base64.h:52
const string base64_chars
Definition: base64.h:47
vector< BYTE > decode(string const &encoded_string)
Definition: base64.h:100
string encode(BYTE const *buf, unsigned int bufLen)
Definition: base64.h:56
these methods convert byte arrays in to base64 codes and are used in BRIDGES to represent the color a...
Definition: alltypes.h:4
unsigned char BYTE
Definition: base64.h:43