Char *base64_encode (char *bindata, char *base64, int binlength) { int i = 0; int j = 0; int current = 0; for (i = 0; i < binlength; i &NBSP;+=&NBSP;3) { //get the first 6-bit current = (* (bindata+i) >> 2) & 0x3F; * (base64 + j++) = base64char[current]; //gets the first two bits of the second 6-bit &NBsp; current = (* (bindata+i) << 4) & 0x30; //If there is only one character, then special handling is required if (binlength <= (i+1)) { * (base64 + j++) = base64char[current]; * (base64 + j++) = ' = '; * (base64 + j++) = ' = '; break; } //get the second 6-bit post four bit current |= (* (bindata+i+1) >> 4 ) & 0xf; * (base64 + j++) = base64char[current]; //get the third 6-bit top four current = (* (bindata+i+1) << 2 ) & 0x3c; if (binLength <= (i+2) { * (base64 + j++) = base64char[current ]; * (base64 + j++) = ' = '; break; } //gets the third 6 bit of the second two digits current | = (* (bindata+i+2) >> 6) & 0x03; * (base64 + j++) = base64char[current]; //get fourth 6-bit current = * ( BINDATA+I+2) & 0x3F; * (base64 + j++) = base64char[current]; } * (base64+j) = '; ' return base64;} Char *base64_decode (char const *base64str, char *debase64str, int Encodestrlen) { int i = 0; int j = 0; int k = 0; char temp[4] = ""; for (i = 0; i < ENCODESTRLEN;&NBSP;I&NBSP;+=&NBSP;4) { for (j = 0; j < 64 ; j++) { if (* (base64str + i) == base64char[j]) { temp[0] = j; } } for (j = 0; j < 64 ; j++) { if (* (base64str + i + 1) == base64char[j]) { temp[1] = j; } } for (j = 0; j < 64 ; j++) { if (* (base64str + i + 2) = =&NBSP;BASE64CHAR[J]) { temp[2] = j; } } for (j = 0; j < 64 ; j++) { if (* (base64str + i + 3) == base64char[j]) { temp[3] = j; } } * (debase64str + k++) = ((temp[0] << 2) &NBSP;&&NBSP;0XFC) | (( TEMP[1]>>4) &&NBSP;0X03); if ( * (base64str + i + 2) == ' = ' ) break; * (debase64str + k++) = ((temp[1] << 4) & 0xf0) | ((temp[2]>>2) & 0x0f); if ( * (base64str + i + 3) == ' = ' ) break; * (debase64str + k++) = ((temp[2] << 6) & 0xf0 ) | (temp[3] & 0x3f); } return debase64str;}
C Language Implementation Base64 encoding, Base64 decoding