Advertisement
Guest User

Untitled

a guest
Sep 24th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.03 KB | None | 0 0
  1. #include <stdio.h>
  2. static char *base64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  3. void base64_encode(const unsigned char *input,int len, unsigned char *output){
  4.   do{
  5.     *output++ = base64[(input[0] & 0xFC ) >> 2];
  6.     if(len==1){
  7.       *output++ = base64[((input[0] & 0x03) << 4 ) ];
  8.       *output++ = '=';
  9.       *output++ = '=';
  10.       break;
  11.     }
  12.     *output++ = base64[
  13.                        ((input[0] & 0x03 ) << 4) | ((input[1] & 0xF0) >> 4)];
  14.     if(len==2){
  15.       *output++ = base64[((input[1] & 0x0F) << 2)];
  16.       *output++ = '=';
  17.       break;
  18.     }
  19.     *output++ = base64[
  20.                        ((input[1] & 0x0F) << 2) | ((input[2] & 0xC0) >> 6)];
  21.     *output++ = base64[(input[2] & 0x3F)];
  22.     input +=3;
  23.   }while(len -=3);
  24.   *output = '\0';
  25.   *output = '\n';
  26. }
  27.                        
  28. int main(int argc, char *argv[]){
  29.   char buffer[100];
  30.   if(argc == 2){
  31.   base64_encode(argv[1],sizeof(argv[1]),&buffer[0]);
  32.   printf(buffer);
  33.   }
  34.   return 0;
  35. }
  36.  
  37. mercie voor te kijken!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement