-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.c
More file actions
33 lines (26 loc) · 816 Bytes
/
test.c
File metadata and controls
33 lines (26 loc) · 816 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <stdio.h>
#include <stdlib.h>
#include "base64.h"
int main() {
/* run example
* 11110000 00110010 10110100 10101010
* |----||- ---||--- -||----| |----||- ----
* 8 D K 0 q g
*/
unsigned char b[] = {0xF0, 0x32, 0xB4, 0xAA};
char *s = malloc(10);
int num_written = b64_encode(b, 4, s);
*(s + num_written) = '\0';
printf("--------ENCODE-TEST--------\nexpected: 8DK0qg\ngot: %s\n", s);
char *s2 = "8DK0qg";
unsigned char *b2 = malloc(10);
num_written = b64_decode(s2, 6, b2);
printf("--------DECODE-TEST--------\nexpected: f0 32 b4 aa\ngot: ");
for(int i = 0; i < num_written; i++) {
printf("%x ", *(b2 + i));
}
printf("\n");
free(s);
free(b2);
return 0;
}