Usage examples and info

This commit is contained in:
Joe DF 2018-07-12 10:09:50 -04:00
parent f2c2b2bb0d
commit 0eceb10024
4 changed files with 59 additions and 1 deletions

View File

@ -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
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

View File

@ -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.

44
b64f.c Normal file
View File

@ -0,0 +1,44 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#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;
}

BIN
picture.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB