summaryrefslogtreecommitdiffstats
path: root/src/onetimebluh.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/onetimebluh.c')
-rw-r--r--src/onetimebluh.c82
1 files changed, 26 insertions, 56 deletions
diff --git a/src/onetimebluh.c b/src/onetimebluh.c
index fed8476..67cefef 100644
--- a/src/onetimebluh.c
+++ b/src/onetimebluh.c
@@ -61,7 +61,7 @@ int main (int argc, char* argv[]) {
break;
case 'c':
if (strlen (argv[optind - 1]) != 2){
- printf ("ERROR: too much or too many characters inserted! You must insert exactly two characters.");
+ eprintf ("ERROR: too much or too many characters inserted! You must insert exactly two characters.");
exit (EXIT_FAILURE);
}
opzioni.chars = argv[optind - 1];
@@ -105,16 +105,14 @@ int main (int argc, char* argv[]) {
} else if (sip[0] == 'T') {
opzioni.nbytes = opzioni.nbytes*1024*1024*1024*1024;
} else if (sip[0] != '\0') {
- printf ("ERROR: you must specify the size in KiB, MiB, GiB or TiB, respectively using K, M, G or T, or nothing for just bytes.");
+ eprintf ("ERROR: you must specify the size in KiB, MiB, GiB or TiB, respectively using K, M, G or T, or nothing for just bytes.");
exit (EXIT_FAILURE);
}
break;
case 'o':
opzioni.output = argv[optind-1];
if (!access (opzioni.output, F_OK)) {
- if (!opzioni.quiet) {
- printf ("WARNING: %s file exists in filesystem and will be overwritten!", opzioni.output);
- }
+ qprintf (opzioni.quiet, "WARNING: %s file exists in filesystem and will be overwritten!", opzioni.output);
}
break;
case 'q':
@@ -137,16 +135,16 @@ int main (int argc, char* argv[]) {
/* Next section performs some input checks */
if (!command) {
- printf ("ERROR: no command called\n");
+ eprintf ("ERROR: no command called\n");
exit (EXIT_FAILURE);
} else if (command > 1) {
- printf ("ERROR: multiple commands called\n");
- printf ("%s [COMMAND] [OPTIONS] ...\n", argv[0]);
+ eprintf ("ERROR: multiple commands called\n");
+ eprintf ("%s [COMMAND] [OPTIONS] ...\n", argv[0]);
exit (EXIT_FAILURE);
}
if (optind < argc) {
- printf ("ERROR: too many arguments\n");
+ eprintf ("ERROR: too many arguments\n");
exit (EXIT_FAILURE);
}
@@ -154,7 +152,7 @@ int main (int argc, char* argv[]) {
if (opzioni.comm == 'e' || opzioni.comm == 'd') {
if (!opzioni.keyfile) {
- printf ("ERROR: no key specified\n");
+ eprintf ("ERROR: no key specified\n");
exit (EXIT_FAILURE);
}
xor (&opzioni);
@@ -177,9 +175,7 @@ void xor (Opts* opzioni) {
if (opzioni->input) {
mex = fopen (opzioni->input, "r");
} else if (!opzioni->input) {
- if (!opzioni->quiet) {
- printf("INFO: Reading from standard input (press ^D to insert the EOF character when you are finished):\n");
- }
+ qprintf(opzioni->quiet, "INFO: Reading from standard input (press ^D to insert the EOF character when you are finished):\n");
input = readInput (stdin, 8);
}
@@ -208,9 +204,7 @@ void xor (Opts* opzioni) {
if (opzioni->output) {
fwrite (bytes, sizeof(char), mess_size, critt);
} else if (!opzioni->output) {
- if (!opzioni->quiet) {
- printf ("WARNING: output not specified, printing to standard output\n");
- }
+ qprintf (opzioni->quiet, "WARNING: output not specified, printing to standard output\n");
fprintf (stdout, "%s", bytes);
@@ -226,10 +220,8 @@ void xor (Opts* opzioni) {
ftruncate (fileno (keyx), (pad_size - mess_size));
fseek (keyx, 0L, SEEK_END);
int64_t new_pad_size = ftell (keyx);
- if (!opzioni->quiet) {
- printf ("INFO: your pad is now %li bytes shorter\n", mess_size);
- printf ("INFO: you now have %li bytes left\n", new_pad_size);
- }
+ qprintf (opzioni->quiet, "INFO: your pad is now %li bytes shorter\n", mess_size);
+ qprintf (opzioni->quiet, "INFO: you now have %li bytes left\n", new_pad_size);
}
free (bytes);
@@ -247,13 +239,9 @@ void xor (Opts* opzioni) {
}
if (opzioni->comm == 'e') {
- if (!opzioni->quiet) {
- printf ("INFO: message successfully encrypted\n");
- }
+ qprintf (opzioni->quiet, "INFO: message successfully encrypted\n");
} else if (opzioni->comm == 'd') {
- if (!opzioni->quiet) {
- printf ("INFO: message successfully decrypted\n");
- }
+ qprintf (opzioni->quiet, "INFO: message successfully decrypted\n");
}
return;
@@ -262,20 +250,16 @@ void xor (Opts* opzioni) {
void keyrand (Opts* opzioni) {
if (opzioni->nbytes < -1) { // orribile
- printf ("ERROR: negative byte value inserted!\n");
+ eprintf ("ERROR: negative byte value inserted!\n");
exit (EXIT_FAILURE);
} else if (opzioni->nbytes) {
if(opzioni->nbytes == -1) {
- if (!opzioni->quiet) {
- printf ("WARNING: no byte number specified, using default value: 1MB\n");
- }
+ qprintf (opzioni->quiet, "WARNING: no byte number specified, using default value: 1MB\n");
opzioni->nbytes = 1048576;
}
- if (!opzioni->quiet) {
- printf ("INFO: generating pad...\n");
- }
+ qprintf (opzioni->quiet, "INFO: generating pad...\n");
unsigned char* key = malloc (opzioni->nbytes);
RAND_bytes (key, opzioni->nbytes);
@@ -288,13 +272,9 @@ void keyrand (Opts* opzioni) {
fclose (file);
free (key);
- if (!opzioni->quiet) {
- printf ("INFO: created key file %s of %ld bytes\n", opzioni->output, opzioni->nbytes);
- }
+ qprintf (opzioni->quiet, "INFO: created key file %s of %ld bytes\n", opzioni->output, opzioni->nbytes);
} else if (!opzioni->output) {
- if (!opzioni->quiet) {
- printf ("WARNING: output not specified, printing to standard output\n");
- }
+ qprintf (opzioni->quiet, "WARNING: output not specified, printing to standard output\n");
fprintf (stdout, "%s", key);
free (key);
@@ -305,8 +285,8 @@ void keyrand (Opts* opzioni) {
}
} else {
- printf ("WARNING: byte number specified is 0.\n");
- printf ("WARNING: doing nothing!\n");
+ eprintf ("WARNING: byte number specified is 0.\n");
+ eprintf ("WARNING: doing nothing!\n");
}
return;
@@ -321,9 +301,7 @@ void bluh (Opts* opzioni) {
if (opzioni->input) {
mex = fopen (opzioni->input, "r");
} else if (!opzioni->input) {
- if (!opzioni->quiet) {
- printf("INFO: Reading from standard input (press ^D to insert the EOF character when you are finished):\n");
- }
+ qprintf(opzioni->quiet, "INFO: Reading from standard input (press ^D to insert the EOF character when you are finished):\n");
input = readInput (stdin, 8);
}
@@ -356,9 +334,7 @@ void bluh (Opts* opzioni) {
if (opzioni->output) {
fwrite (bits, sizeof(char), (8 * len), bluh);
} else if (!opzioni->output) {
- if (!opzioni->quiet) {
- printf ("WARNING: output not specified, printing to standard output\n");
- }
+ qprintf (opzioni->quiet, "WARNING: output not specified, printing to standard output\n");
fprintf (stdout, "%s", bits);
@@ -373,9 +349,7 @@ void bluh (Opts* opzioni) {
free (bits);
- if (!opzioni->quiet) {
- printf ("INFO: message successfully bluhed!\n");
- }
+ qprintf (opzioni->quiet, "INFO: message successfully bluhed!\n");
} else if (opzioni->comm == 'u') {
char* bits;
@@ -392,9 +366,7 @@ void bluh (Opts* opzioni) {
if (opzioni->output) {
fwrite (comp, sizeof(char), (len / 8), bluh);
} else if (!opzioni->output) {
- if (!opzioni->quiet) {
- printf ("WARNING: output not specified, printing to standard output\n");
- }
+ qprintf (opzioni->quiet, "WARNING: output not specified, printing to standard output\n");
fprintf (stdout, "%s", comp);
@@ -409,9 +381,7 @@ void bluh (Opts* opzioni) {
free (comp);
- if (!opzioni->quiet) {
- printf ("INFO: message successfully unbluhed!\n");
- }
+ qprintf (opzioni->quiet, "INFO: message successfully unbluhed!\n");
}
if (opzioni->input) {