Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.49 KB | None | 0 0
  1. #ifndef _BASE64_H
  2. #define _BASE64_H
  3.  
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <ctype.h>
  7. #include <stdbool.h>
  8.  
  9. /*DEFINICION CONSTANTES*/
  10. #define EMPTYBASE256 '\0'
  11. #define EMPTYBASE64 '='
  12.  
  13. /*Tabla de simbolos Base64*/
  14. static const char base64_table[] = {
  15.         'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
  16.         'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
  17.         'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
  18.         'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
  19.         'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
  20.         'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  21.         'w', 'x', 'y', 'z', '0', '1', '2', '3',
  22.         '4', '5', '6', '7', '8', '9', '+', '/'
  23. };
  24.  
  25. /*Recibe:
  26.  *       Buffer con 3 caracteres en Base256
  27.  *       Buffer para guardar el resultado de la codificacion
  28.  *       Cantidad de caracteres a encodear (que no son padding)
  29.  *
  30.  *Codifica el contenido en Base256 a Base64 y lo guarda en el buffer resultado*/
  31. bool base64_encode(const unsigned char* source_code, unsigned char* result, int char_to_encode);
  32.  
  33. /*Recibe:
  34.  *       Buffer conteniendo 4 bytes en Base64
  35.  *       Buffer de 3 bytes en Base256 para guardar el resultado
  36.  *       Puntero a int que apunta a un entero que guarda la cantidad de caracteres a escribir (que no son padding)
  37.  *
  38.  * Decodifica el contenido en Base64 y de ser una decodificacion existosa lo guarda
  39.  * en el buffer result y devuelve True. Sino, devuelve False*/
  40. bool base64_decode(const unsigned char* source_code, unsigned char* result, int* write);
  41.  
  42. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement