Usage examples and info
This commit is contained in:
parent
f2c2b2bb0d
commit
0eceb10024
13
BuildRun.bat
13
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
|
||||
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
|
|
@ -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.
|
|
@ -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;
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 27 KiB |
Loading…
Reference in New Issue