40 #define _MPRINTF_REPLACE
49 static void decodeQuantum(
unsigned char *dest,
const char *
src)
53 for(i = 0; i < 4; i++) {
54 if(src[i] >=
'A' && src[i] <=
'Z')
55 x = (x << 6) + (
unsigned int)(src[
i] -
'A' + 0);
56 else if(src[i] >=
'a' && src[i] <=
'z')
57 x = (x << 6) + (
unsigned int)(src[
i] -
'a' + 26);
58 else if(src[i] >=
'0' && src[i] <=
'9')
59 x = (x << 6) + (
unsigned int)(src[
i] -
'0' + 52);
60 else if(src[i] ==
'+')
62 else if(src[i] ==
'/')
64 else if(src[i] ==
'=')
68 dest[2] = (
unsigned char)(x & 255);
70 dest[1] = (
unsigned char)(x & 255);
72 dest[0] = (
unsigned char)(x & 255);
87 unsigned char lastQuantum[3];
90 while((src[length] !=
'=') && src[length])
92 while(src[length+equalsTerm] ==
'=')
95 numQuantums = (length + equalsTerm) / 4;
97 rawlen = (numQuantums * 3) - equalsTerm;
99 for(i = 0; i < numQuantums - 1; i++) {
100 decodeQuantum((
unsigned char *)dest, src);
104 decodeQuantum(lastQuantum, src);
105 for(i = 0; i < 3 - equalsTerm; i++)
106 dest[i] = lastQuantum[i];
112 static char table64[]=
113 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
125 unsigned char ibuf[3];
126 unsigned char obuf[4];
132 char *indata = (
char *)inp;
135 insize = strlen(indata);
137 base64data = output = (
char*)malloc(insize*4/3+4);
142 for (i = inputparts = 0; i < 3; i++) {
153 obuf [0] = (ibuf [0] & 0xFC) >> 2;
154 obuf [1] = ((ibuf [0] & 0x03) << 4) | ((ibuf [1] & 0xF0) >> 4);
155 obuf [2] = ((ibuf [1] & 0x0F) << 2) | ((ibuf [2] & 0xC0) >> 6);
156 obuf [3] = ibuf [2] & 0x3F;
181 *outptr = base64data;
183 return strlen(base64data);
196 #define TEST_NEED_SUCK
199 int main(
int argc,
char **argv,
char **envp)
206 data = (
unsigned char *)suck(&dataLen);
209 fprintf(stderr,
"%d\n", base64Len);
210 fprintf(stdout,
"%s", base64);
212 free(base64); free(data);
225 #define TEST_NEED_SUCK
228 int main(
int argc,
char **argv,
char **envp)
236 base64 = (
char *)suck(&base64Len);
237 data = (
unsigned char *)malloc(base64Len * 3/4 + 8);
240 fprintf(stderr,
"%d\n", dataLen);
242 for(i=0; i < dataLen; i+=0x10) {
243 printf(
"0x%02x: ", i);
244 for(j=0; j < 0x10; j++)
246 printf(
"%02x ", data[i+j]);
252 for(j=0; j < 0x10; j++)
254 printf(
"%c", isgraph(data[i+j])?data[i+j]:
'.');
260 free(base64); free(data);
265 #ifdef TEST_NEED_SUCK
267 void *suck(
int *lenptr)
270 unsigned char *buf =
NULL;
276 buf = (
unsigned char *)realloc(buf, cursize);
277 memset(buf + len, 0, cursize - len);
278 lastread =
fread(buf + len, 1, cursize - len, stdin);
280 }
while(!feof(stdin));
size_t Curl_base64_encode(const char *inp, size_t insize, char **outptr)
size_t Curl_base64_decode(const char *src, char *dest)
GLsizei GLsizei GLenum GLenum const GLvoid * data
GLsizei const GLcharARB const GLint * length
int sprintf(idStr &string, const char *fmt,...)