From 9b8db1697f9e05a447aa7710167c67bbd8c59cbd Mon Sep 17 00:00:00 2001 From: Seppia Date: Wed, 4 Jul 2018 15:39:33 +0200 Subject: Syntax change Syntax for string evaluation changed to a more concise version. --- src/onetimebluh.c | 62 +++++++++++++++++++++++++++---------------------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/src/onetimebluh.c b/src/onetimebluh.c index 6dfc2ef..e657dd2 100644 --- a/src/onetimebluh.c +++ b/src/onetimebluh.c @@ -164,7 +164,7 @@ int main (int argc, char* argv[]) { /* Next section detects the functions to call */ if (opzioni.comm == 'e' || opzioni.comm == 'd') { - if (opzioni.keyfile == NULL) { + if (!opzioni.keyfile) { printf ("ERROR: no key specified\n"); exit (EXIT_FAILURE); } @@ -205,25 +205,25 @@ void xor (Opts* opzioni) { FILE* mex; FILE* keyx = fopen (opzioni->keyfile, "r+"); - if (opzioni->input != NULL) { + if (opzioni->input) { mex = fopen (opzioni->input, "r"); - } else if (opzioni->input == NULL) { + } else if (!opzioni->input) { printf("INFO: Reading from standard input (press ^D to insert the EOF character when you are finished):\n"); input = readInput (stdin, 8); } - if (opzioni->output != NULL) { + if (opzioni->output) { critt = fopen (opzioni->output, "w"); } int64_t mess_size; int64_t pad_size; - if (opzioni->input != NULL) { + if (opzioni->input) { fseek (mex, 0L, SEEK_END); mess_size = ftell (mex); rewind (mex); - } else if (opzioni->input == NULL) { + } else if (!opzioni->input) { mess_size = strlen (input); } @@ -236,13 +236,13 @@ void xor (Opts* opzioni) { int64_t i; char a, b; - if (opzioni->input != NULL) { + if (opzioni->input) { for (i = 0; i < mess_size; i ++) { fscanf (mex, "%c", &a); fscanf (keyx, "%c", &b); bytes[i] = a ^ b; } - } else if (opzioni->input == NULL) { + } else if (!opzioni->input) { for (i = 0; i < mess_size; i ++) { a = input[i]; fscanf (keyx, "%c", &b); @@ -250,9 +250,9 @@ void xor (Opts* opzioni) { } } - if (opzioni->output != NULL) { + if (opzioni->output) { fwrite (bytes, sizeof(char), mess_size, critt); - } else if (opzioni->output == NULL) { + } else if (!opzioni->output) { if (!opzioni->quiet) { printf ("WARNING: output not specified, printing to standard output\n"); } @@ -279,11 +279,11 @@ void xor (Opts* opzioni) { fclose (keyx); - if (opzioni->input != NULL) { + if (opzioni->input) { fclose (mex); } - if (opzioni->output != NULL) { + if (opzioni->output) { fclose (critt); } @@ -322,7 +322,7 @@ void keyrand (Opts* opzioni) { RAND_bytes (key, opzioni->nbytes); FILE* file; - if (opzioni->output != NULL) { + if (opzioni->output) { file = fopen (opzioni->output, "w"); fwrite (key, sizeof(char), opzioni->nbytes, file); fclose (file); @@ -331,7 +331,7 @@ void keyrand (Opts* opzioni) { if (!opzioni->quiet) { printf ("INFO: created key file %s of %ld bytes\n", opzioni->output, opzioni->nbytes); } - } else if (opzioni->output == NULL) { + } else if (!opzioni->output) { if (!opzioni->quiet) { printf ("WARNING: output not specified, printing to standard output\n"); } @@ -360,34 +360,34 @@ void bluh (Opts* opzioni) { FILE* bluh; FILE* mex; - if (opzioni->input != NULL) { + if (opzioni->input) { mex = fopen (opzioni->input, "r"); - } else if (opzioni->input == NULL) { + } else if (!opzioni->input) { printf("INFO: Reading from standard input (press ^D to insert the EOF character when you are finished):\n"); input = readInput (stdin, 8); } - if (opzioni->output != NULL) { + if (opzioni->output) { bluh = fopen (opzioni->output, "w"); } int64_t len; - if (opzioni->input != NULL) { + if (opzioni->input) { fseek (mex, 0L, SEEK_END); len = ftell (mex); rewind (mex); - } else if (opzioni->input == NULL) { + } else if (!opzioni->input) { len = strlen (input); } if (opzioni->comm == 'b') { char* bytes; - if (opzioni->input != NULL) { + if (opzioni->input) { bytes = malloc (len); fread (bytes, sizeof(char), len, mex); - } else if (opzioni->input == NULL) { + } else if (!opzioni->input) { bytes = input; } @@ -401,9 +401,9 @@ void bluh (Opts* opzioni) { } } - if (opzioni->output != NULL) { + if (opzioni->output) { fwrite (bits, sizeof(char), (8 * len), bluh); - } else if (opzioni->output == NULL) { + } else if (!opzioni->output) { if (!opzioni->quiet) { printf ("WARNING: output not specified, printing to standard output\n"); } @@ -415,7 +415,7 @@ void bluh (Opts* opzioni) { } } - if (opzioni->input != NULL) { + if (opzioni->input) { free (bytes); } @@ -428,10 +428,10 @@ void bluh (Opts* opzioni) { } else if (opzioni->comm == 'u') { char* bits; - if (opzioni->input != NULL) { + if (opzioni->input) { bits = malloc (len); fread (bits, sizeof(char), len, mex); - } else if (opzioni->input == NULL) { + } else if (!opzioni->input) { bits = input; } @@ -449,9 +449,9 @@ void bluh (Opts* opzioni) { } } - if (opzioni->output != NULL) { + if (opzioni->output) { fwrite (comp, sizeof(char), (len / 8), bluh); - } else if (opzioni->output == NULL ) { + } else if (!opzioni->output) { if (!opzioni->quiet) { printf ("WARNING: output not specified, printing to standard output\n"); } @@ -463,7 +463,7 @@ void bluh (Opts* opzioni) { } } - if (opzioni->input != NULL) { + if (opzioni->input) { free (bits); } @@ -474,11 +474,11 @@ void bluh (Opts* opzioni) { } } - if (opzioni->input != NULL) { + if (opzioni->input) { fclose (mex); } - if (opzioni->output != NULL) { + if (opzioni->output) { fclose (bluh); } -- cgit v1.2.3