Advertisement
Guest User

Untitled

a guest
Sep 24th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.00 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.     }#include <stdio.h>
  19. static char *base64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  20. void base64_encode(const unsigned char *input,int len, unsigned char *output){
  21.   do{
  22.     *output++ = base64[(input[0] & 0xFC ) >> 2];
  23.     if(len==1){
  24.       *output++ = base64[((input[0] & 0x03) << 4 ) ];
  25.       *output++ = '=';
  26.       *output++ = '=';
  27.       break;
  28.     }
  29.     *output++ = base64[
  30.                        ((input[0] & 0x03 ) << 4) | ((input[1] & 0xF0) >> 4)];
  31.     if(len==2){
  32.       *output++ = base64[((input[1] & 0x0F) << 2)];
  33.       *output++ = '=';
  34.       break;
  35.     }
  36.     *output++ = base64[
  37.                        ((input[1] & 0x0F) << 2) | ((input[2] & 0xC0) >> 6)];
  38.     *output++ = base64[(input[2] & 0x3F)];
  39.     input +=3;
  40.   }while(len -=3);
  41.   *output = '\0';
  42.   *output = '\n';
  43. }
  44.                        
  45. int main(int argc, char *argv[]){
  46.   char buffer[100];
  47.   if(argc == 2){
  48.   base64_encode(argv[1],sizeof(argv[1]),&buffer[0]);
  49.   printf(buffer);
  50.   }
  51.   return 0;
  52. }
  53.  
  54.     *output++ = base64[
  55.                        ((input[1] & 0x0F) << 2) | ((input[2] & 0xC0) >> 6)];
  56.     *output++ = base64[(input[2] & 0x3F)];
  57.     input +=3;
  58.   }while(len -=3);
  59.   *output = '\0';
  60.   *output = '\n';
  61. }
  62.                        
  63. int main(int argc, char *argv[]){
  64.   char buffer[100];
  65.   if(argc == 2){
  66.   base64_encode(argv[1],sizeof(argv[1]),&buffer[0]);
  67.   printf(buffer);
  68.   }
  69.   return 0;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement