-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
29 lines (27 loc) · 840 Bytes
/
main.c
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
//
// Created by william bright on 5/9/20.
//
#include "base64.h"
#include "urlsafe.h"
#include <stdlib.h>
#include <string.h>
#include <assert.h>
int main(void){
char word[] = "Hello world!";
int wordlen = sizeof(word);
char *decoded;
char *encoded;
// encode our word
encoded = (char *) malloc((size_t ) (Base64encode_len(wordlen)));
encodeURLSafeWithPadding(encoded, Base64encode_len(wordlen), word, wordlen);
// decode it
int encoded_length = length(encoded);
decoded = (char *) malloc((size_t ) (encoded_length));
decodeURLSafe(decoded, encoded, encoded_length);
// check they are the same string, 0 means its equal
assert(strcmp(word, decoded) == 0);
// free the memory otherwise it will delete your favorite cat pictures
free(encoded);
free(decoded);
return 0;
}