Skip to content

AICDEV/base64

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

base64

Small and simple base64 library programmed in C. Currently ONLY tested and developt on little endian systems! Keep that in mind!

Benchmark

Measured were (10000 * 250 ) encoding calls.

Plot

Compile

To compile the library, simply run the script 'build.sh'. Or directly in your bash:

gcc base.c ./lib/b64.c -Wall -O3 -s -std=c99 -o base

Encodind with compiled bin

./base "base64 implementation makes fun"
YmFzZTY0IGltcGxlbWVudGF0aW9uIG1ha2VzIGZ1bg==

Decoding with compiled bin

./base -d YmFzZTY0IGltcGxlbWVudGF0aW9uIG1ha2VzIGZ1bg==
base64 implementation makes fun

Usage in your C program

If you only want to use the library, you can find a complete example in the base.c file.

#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#include "./lib/b64.h"


void usage() {
    printf("encode: './b4 <value>'\n");
    printf("decode: './b4 -d <value>'\n");
}

int main(int argc, char *argv[]) {

    if (argc == 2) {
        
        char *input = argv[1];
        b64_encoded_t *b_out = encode_base_64(input);

        printf("%s\n", b_out);
        free(b_out);
       
    } else if (argc == 3) {
     
        char *input = argv[2];
        b64_decoded_t *b_out = decode_base64(input);
        
        printf("%s\n", b_out);
        free(b_out);
    } else {
        usage();
        return EXIT_FAILURE;
    }
}

Testing

The test is written in python. Simple run the following commands for testing:

#decoding test
python3 decoding_test.py

#encoding test
python3 encoding_test.py

About

Base64 lib written in pure C.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages