From c3e4df90f4372dd38de7fe199ccbdcbc38c6c416 Mon Sep 17 00:00:00 2001 From: Seppia Date: Fri, 8 Sep 2017 02:38:59 +0200 Subject: Code Style changed. Added space between functions names and arguments calls. --- src/onetimebluh.c | 206 +++++++++++++++++++++++++++--------------------------- 1 file changed, 103 insertions(+), 103 deletions(-) (limited to 'src') diff --git a/src/onetimebluh.c b/src/onetimebluh.c index c28a5af..8c54f0e 100644 --- a/src/onetimebluh.c +++ b/src/onetimebluh.c @@ -7,12 +7,12 @@ #include #include -void xor(int ed, char* mess, char* keyf, char* outp); /* operates the bitwise XOR between mess and keyf and puts the output to outp */ -void keyrand(int nb, char* outp); /* generates random numbers using RAND_bytes from openssl and puts them into outp */ -void bluh(int c, char* mess, char* outp, char* ch); /* performs the binary dump of the input file and prints that to outp */ -void help(char* av[]); /* prints the help message */ +void xor (int ed, char* mess, char* keyf, char* outp); /* operates the bitwise XOR between mess and keyf and puts the output to outp */ +void keyrand (int nb, char* outp); /* generates random numbers using RAND_bytes from openssl and puts them into outp */ +void bluh (int c, char* mess, char* outp, char* ch); /* performs the binary dump of the input file and prints that to outp */ +void help (char* av[]); /* prints the help message */ -int main(int argc, char* argv[]) { +int main (int argc, char* argv[]) { int opt = 1; int command = 0; @@ -44,22 +44,22 @@ int main(int argc, char* argv[]) { {0, 0, 0, 0}, }; - if ((opt = getopt_long(argc, argv, "b:c:d:e:ghk:n:o:tu:", options, &option_index)) == -1) + if ((opt = getopt_long (argc, argv, "b:c:d:e:ghk:n:o:tu:", options, &option_index)) == -1) break; switch (opt) { case 'b': message = argv[optind-1]; - if (access(message, F_OK) == -1) { /* look at next comment */ - error(errno, errno, message); + if (access (message, F_OK) == -1) { /* look at next comment */ + error (errno, errno, message); } command ++; comm = 'b'; break; case 'c': - if (strlen(argv[optind - 1]) != 2){ - printf("Too much or too many characters inserted!"); - exit(EXIT_FAILURE); + if (strlen (argv[optind - 1]) != 2){ + printf ("Too much or too many characters inserted!"); + exit (EXIT_FAILURE); } chars = argv[optind - 1]; break; @@ -70,8 +70,8 @@ int main(int argc, char* argv[]) { break; case 'e': message = argv[optind-1]; - if (access(message, F_OK) == -1) { /* checks the existence of the file and eventually exits */ - error(errno, errno, message); + if (access (message, F_OK) == -1) { /* checks the existence of the file and eventually exits */ + error (errno, errno, message); } command ++; comm = 'e'; @@ -81,17 +81,17 @@ int main(int argc, char* argv[]) { comm = 'g'; break; case 'h': - help(argv); + help (argv); command ++; break; case 'k': keyfile = argv[optind-1]; - if (access(keyfile, F_OK) == -1) { /* look at the previous comment */ - error(errno, errno, keyfile); + if (access (keyfile, F_OK) == -1) { /* look at the previous comment */ + error (errno, errno, keyfile); } break; case 'n': - nbytes = atoi(argv[optind-1]); + nbytes = atoi (argv[optind-1]); break; case 'o': output = argv[optind-1]; @@ -101,8 +101,8 @@ int main(int argc, char* argv[]) { break; case 'u': message = argv[optind-1]; - if (access(message, F_OK) == -1) { /* just guess */ - error(errno, errno, message); + if (access (message, F_OK) == -1) { /* just guess */ + error (errno, errno, message); } command ++; comm = 'u'; @@ -110,47 +110,47 @@ int main(int argc, char* argv[]) { case '?': break; default: - printf("carachter code returned 0%o \n", opt); + printf ("carachter code returned 0%o \n", opt); } } /* Next section performs some input checks */ if (command == 0) { - printf("%s: No command called\n", argv[0]); - exit(EXIT_FAILURE); + printf ("%s: No command called\n", argv[0]); + exit (EXIT_FAILURE); } else if (command > 1) { - printf("Multiple commands called\n"); - printf("%s [COMMAND] [OPTIONS] ...\n", argv[0]); - exit(EXIT_FAILURE); + printf ("Multiple commands called\n"); + printf ("%s [COMMAND] [OPTIONS] ...\n", argv[0]); + exit (EXIT_FAILURE); } if (optind < argc) { - printf("%s: Too many arguments\n", argv[0]); - exit(EXIT_FAILURE); + printf ("%s: Too many arguments\n", argv[0]); + exit (EXIT_FAILURE); } /* Next section detects the functions to call */ if (comm == 'e' || comm == 'r') { if (keyfile == NULL) { - printf("%s: No key specified: exit!\n", argv[0]); - exit(EXIT_FAILURE); + printf ("%s: No key specified: exit!\n", argv[0]); + exit (EXIT_FAILURE); } if (tear == 1) { comm++; } - xor(comm, message, keyfile, output); + xor (comm, message, keyfile, output); } else if (comm == 'g') { - keyrand(nbytes, output); + keyrand (nbytes, output); } else if (comm == 'b' || comm == 'u') { - bluh(comm, message, output, chars); + bluh (comm, message, output, chars); } - exit(EXIT_SUCCESS); + exit (EXIT_SUCCESS); } -void xor(int ed, char* mess, char* keyf, char* outp) { +void xor (int ed, char* mess, char* keyf, char* outp) { char* defenoutp = "critt"; char* defdeoutp = "decritt"; @@ -159,107 +159,107 @@ void xor(int ed, char* mess, char* keyf, char* outp) { if (outp == NULL) { if (ed == 'e' || ed == 'f') { - printf("WARNING no output name specified using default value 'critt' \n"); + printf ("WARNING no output name specified using default value 'critt' \n"); outp = defenoutp; } else if (ed == 'r' || ed == 's') { - printf("WARNING no output name specified usign default value 'decritt' \n"); + printf ("WARNING no output name specified usign default value 'decritt' \n"); outp = defdeoutp; } } - FILE* mex = fopen(mess, "r"); - FILE* keyx = fopen(keyf, "r+"); - FILE* critt = fopen(outp, "w"); + FILE* mex = fopen (mess, "r"); + FILE* keyx = fopen (keyf, "r+"); + FILE* critt = fopen (outp, "w"); long mess_size; long pad_size; - fseek(mex, 0L, SEEK_END); - mess_size = ftell(mex); - rewind(mex); - fseek(keyx, 0L, SEEK_END); - pad_size = ftell(keyx); - fseek(keyx, (pad_size - mess_size), SEEK_SET); + fseek (mex, 0L, SEEK_END); + mess_size = ftell (mex); + rewind (mex); + fseek (keyx, 0L, SEEK_END); + pad_size = ftell (keyx); + fseek (keyx, (pad_size - mess_size), SEEK_SET); - char* bytes = malloc(mess_size); + char* bytes = malloc (mess_size); long i; char a, b; for (i = 0; i < mess_size; i ++) { - fscanf(mex, "%c", &a); - fscanf(keyx, "%c", &b); + fscanf (mex, "%c", &a); + fscanf (keyx, "%c", &b); bytes[i] = a ^ b; } - fwrite(bytes, sizeof(char), mess_size, critt); + fwrite (bytes, sizeof(char), mess_size, critt); if (ed == 'f' || ed == 's') { - ftruncate(fileno(keyx), (pad_size - mess_size)); - fseek(keyx, 0L, SEEK_END); - long new_pad_size = ftell(keyx); - printf("Your pad is now %li bytes shorter \n", mess_size); - printf("You now have %li bytes left \n", new_pad_size); + ftruncate (fileno (keyx), (pad_size - mess_size)); + fseek (keyx, 0L, SEEK_END); + long new_pad_size = ftell (keyx); + printf ("Your pad is now %li bytes shorter \n", mess_size); + printf ("You now have %li bytes left \n", new_pad_size); } - free(bytes); + free (bytes); - fclose(mex); - fclose(keyx); - fclose(critt); + fclose (mex); + fclose (keyx); + fclose (critt); if (ed == 'e' || ed == 'f') { - printf("Message successfully encrypted \n"); + printf ("Message successfully encrypted \n"); } else if (ed == 'r' || ed == 's') { - printf("Message successfully decrypted \n"); + printf ("Message successfully decrypted \n"); } return; } -void keyrand(int nb, char* outp) { +void keyrand (int nb, char* outp) { char* defoutp = "default.key"; /* Next block controls the inputs and eventually sets the default values */ if((nb == -1) && (outp == NULL)) { - printf("WARNING no option specified usign default values... \n"); + printf ("WARNING no option specified usign default values... \n"); nb = 1048576; outp = defoutp; } if (nb < -1) { // orribile - printf("Negative byte value inserted! \n"); - printf("Exiting... \n"); - exit(EXIT_FAILURE); + printf ("Negative byte value inserted! \n"); + printf ("Exiting... \n"); + exit (EXIT_FAILURE); } else if (nb != 0) { if(nb == -1) { - printf("No byte number specified... using default value: 1MB \n"); + printf ("No byte number specified... using default value: 1MB \n"); nb = 1048576; } - unsigned char* key = malloc(nb); - RAND_bytes(key, nb); + unsigned char* key = malloc (nb); + RAND_bytes (key, nb); if (outp == NULL) { outp = defoutp; - printf("No output name specified... using default value: default.key \n"); + printf ("No output name specified... using default value: default.key \n"); } - FILE* file = fopen(outp, "w"); - fwrite(key, sizeof(char), nb, file); - fclose(file); - free(key); - printf("Created key file %s of %d bytes \n", outp, nb); + FILE* file = fopen (outp, "w"); + fwrite (key, sizeof(char), nb, file); + fclose (file); + free (key); + printf ("Created key file %s of %d bytes \n", outp, nb); } else { - printf("Byte number specified is 0. \n"); - printf("Doing nothing! \n"); + printf ("Byte number specified is 0. \n"); + printf ("Doing nothing! \n"); } return; } -void bluh(int c, char* mess, char* outp, char* ch) { +void bluh (int c, char* mess, char* outp, char* ch) { char* defbluh = "bluhed"; char* defunbluh = "unbluhed"; @@ -270,28 +270,28 @@ void bluh(int c, char* mess, char* outp, char* ch) { if (outp == NULL) { if (c == 'b') { - printf("WARNING no output name specified using default value 'bluhed' \n"); + printf ("WARNING no output name specified using default value 'bluhed' \n"); outp = defbluh; } else if (c == 'u') { - printf("WARNING no output name specified usign default value 'unbluhed' \n"); + printf ("WARNING no output name specified usign default value 'unbluhed' \n"); outp = defunbluh; } } - FILE* mex = fopen(mess, "r"); - FILE* bluh = fopen(outp, "w"); + FILE* mex = fopen (mess, "r"); + FILE* bluh = fopen (outp, "w"); long len; - fseek(mex, 0L, SEEK_END); - len = ftell(mex); - rewind(mex); + fseek (mex, 0L, SEEK_END); + len = ftell (mex); + rewind (mex); if (c == 'b') { - char* bytes = malloc(len); - char* bits = malloc(8 * len); + char* bytes = malloc (len); + char* bits = malloc (8 * len); - fread(bytes, sizeof(char), len, mex); + fread (bytes, sizeof(char), len, mex); int i,j; @@ -301,18 +301,18 @@ void bluh(int c, char* mess, char* outp, char* ch) { } } - fwrite(bits, sizeof(char), (8 * len), bluh); - free(bytes); - free(bits); + fwrite (bits, sizeof(char), (8 * len), bluh); + free (bytes); + free (bits); - printf("Message successfully bluhed!\n"); + printf ("Message successfully bluhed!\n"); } else if (c == 'u') { - char* comp = malloc((len / 8) + 1); - char* bits = malloc(len); + char* comp = malloc ((len / 8) + 1); + char* bits = malloc (len); - fread(bits, sizeof(char), len, mex); - memset(comp, 0, ((len / 8) + 1)); + fread (bits, sizeof(char), len, mex); + memset (comp, 0, ((len / 8) + 1)); int i, j; @@ -324,21 +324,21 @@ void bluh(int c, char* mess, char* outp, char* ch) { } } - fwrite(comp, sizeof(char), (len / 8), bluh); - free(comp); - free(bits); + fwrite (comp, sizeof(char), (len / 8), bluh); + free (comp); + free (bits); - printf("Message successfully unbluhed!\n"); + printf ("Message successfully unbluhed!\n"); } - fclose(mex); - fclose(bluh); + fclose (mex); + fclose (bluh); return; } -void help(char* av[]) { - fprintf(stdout,"ONETIMEBLUH USAGE:\n" +void help (char* av[]) { + fprintf (stdout,"ONETIMEBLUH USAGE:\n" "%s [COMMAND] [OPTIONS]\n\n" "COMMANDS:\n\n" "-b, --bluh=FILE bluhes your message or in other words performs a binary dump\n" -- cgit v1.2.3