diff --git a/BuildRun.bat b/BuildRun.bat index 874ac75..121bd4b 100644 --- a/BuildRun.bat +++ b/BuildRun.bat @@ -3,5 +3,16 @@ mkdir bin 2>NUL cls echo compiling... gcc test.c base64.c -o bin\test.exe +gcc b64f.c base64.c -o bin\b64f.exe echo running... -bin\test.exe \ No newline at end of file +bin\test.exe +echo. +echo Encoding test image "picture.png" to "picture.b64.txt"... +bin\b64f.exe e picture.png picture.b64.txt +echo. +echo Decoding test image from "picture.b64.txt" to "picture.b64.png"... +bin\b64f.exe d picture.b64.txt picture.b64.png +echo. +echo Done. +echo See files manually if the programmed works correctly. +pause \ No newline at end of file diff --git a/README.md b/README.md index 57154cc..58fba4b 100644 --- a/README.md +++ b/README.md @@ -8,3 +8,6 @@ Released under the MIT License Thank you for inspiration: http://www.codeproject.com/Tips/813146/Fast-base-functions-for-encode-decode + +## Usage +Simply include `base64.c` and `base64.h` in your project and see `base64.h` for instructions. \ No newline at end of file diff --git a/b64f.c b/b64f.c new file mode 100644 index 0000000..895dc9e --- /dev/null +++ b/b64f.c @@ -0,0 +1,44 @@ +#include +#include +#include + +#include "base64.h" + +int lower(int a); + +int main(int argc,char** argv) { + + puts("\nbase64.c [Encode/Decode]"); + puts("------------------------------------"); + printf("Use the following to encode:\n\t%s e(ncode) IN_filepath OUT_filepath\n",argv[0]); + printf("Use the following to decode:\n\t%s d(ecode) IN_filepath OUT_filepath\n",argv[0]); + if (argc < 4) { + puts("\nERROR: not enough parameters..."); + return 1; + } + char opt = lower(argv[1][0]); + int bcoded = 0; + switch(opt) { + case 'd': + puts("\nDECODING"); + bcoded = b64_decodef(argv[2],argv[3]); + break; + case 'e': + puts("\nENCODING"); + bcoded = b64_encodef(argv[2],argv[3]); + break; + default: + puts("\nINVALID OPTION"); + bcoded = -1; + } + + printf("\nBytes encoded/decoded: %i\n",bcoded); + + return 0; +} + +int lower(int a) { //https://stackoverflow.com/a/15709023/883015 + if ((a >= 0x41) && (a <= 0x5A)) + a |= 0x20; + return a; +} diff --git a/picture.png b/picture.png new file mode 100644 index 0000000..6b7f5c9 Binary files /dev/null and b/picture.png differ