From 11bb1ef661dc726368b676f9e21b69a05280f12e Mon Sep 17 00:00:00 2001 From: x1phosura Date: Wed, 13 Apr 2022 18:14:37 -0700 Subject: [PATCH] Misc. base64.c tweaks --- .gitignore | 6 +----- set1/src/base64.c | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/.gitignore b/.gitignore index 8c9fd67..356f27e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,3 @@ # general ignore patterns -*.o - -# ignore compiled executables -## set 1 -set1/base64 +*/bin/* diff --git a/set1/src/base64.c b/set1/src/base64.c index 34a2fb2..f9d0960 100644 --- a/set1/src/base64.c +++ b/set1/src/base64.c @@ -1,6 +1,6 @@ #include #include -#include +#include /* * base64.c: reads in raw bytes and converts to/outputs in base64 format @@ -13,7 +13,7 @@ //#define b64_output b64_out_debug size_t out_index = 0; -char out_buf[BUF_LEN]; +uint8_t out_buf[BUF_LEN]; void b64_out_debug(char c) { @@ -25,19 +25,19 @@ void b64_out_debug(char c) char *b64_alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; -void main(int argc, char *argv[]) +int main() { - char c, spoke = 0; - int tmp, alph_index = 0; + int8_t c; + uint8_t tmp = 0, alph_index = 0, spoke = 0; while ((c = getchar()) != EOF) { switch (spoke) { case 0: - alph_index = c >> 2; // get last 6 bits - tmp = (c & 0x03) << 4; // extract last 2 bits + alph_index = c >> 2; // get last 6 bits + tmp = (c & 0x03) << 4; // extract last 2 bits break; case 1: - alph_index = c >> 4; // get last 4 bits + alph_index = c >> 4; // get last 4 bits alph_index += tmp; tmp = (c & 0x0f) << 2; break; @@ -64,5 +64,7 @@ void main(int argc, char *argv[]) } putchar('\n'); + + return EXIT_SUCCESS; }