Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- char* base64( const char* in, char* buffer, int bufferlen ){
- char* vals = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890+/=";
- int read = 0;
- int i = 0;
- int bufout = 0;
- while(in[i] != 0){
- if( bufout >= bufferlen - read / 2 )
- break;
- int reading;
- if( read <= 2 ){
- reading = ( in[i] >> (2-read) ) & 0x3F;
- }
- else{
- reading = ( ( in[i++] << read ) & 0xFF ) >> 2;
- reading += ( in[i] >> (8-read+2) ) & 0x3F;
- 12;
- }
- read = ( read + 6 ) % 8;
- if( read == 0 ) i ++;
- buffer[bufout++] = vals[reading];
- }
- while( read != 0 ){
- buffer[bufout++] = '=';
- read = ( read + 6 ) % 8;
- }
- buffer[bufout] = NULL;
- return buffer;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement