summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSeppia <nonso@insicuri.net>2016-06-09 17:16:10 +0200
committerSeppia <nonso@insicuri.net>2016-06-09 17:16:10 +0200
commitd16925e3b7910735586a36d6f197f624783dbfd3 (patch)
tree5af17cb69b1d94eb369da31ef9d05e4247b89f54
parentb4fdcac63613c7d114b2ccb004fa053577811f2e (diff)
downloadonetimebluh-d16925e3b7910735586a36d6f197f624783dbfd3.tar.gz
onetimebluh-d16925e3b7910735586a36d6f197f624783dbfd3.tar.bz2
onetimebluh-d16925e3b7910735586a36d6f197f624783dbfd3.zip
added option and help to code
-rw-r--r--onetimebluh.c73
1 files changed, 63 insertions, 10 deletions
diff --git a/onetimebluh.c b/onetimebluh.c
index f838db3..b8f3f8c 100644
--- a/onetimebluh.c
+++ b/onetimebluh.c
@@ -1,22 +1,75 @@
#include<stdio.h>
#include<stdlib.h>
+#include<unistd.h>
+
+void xor(int ac, char* av[]);
+void help(char* av[]);
int main(int argc, char* argv[]) {
- FILE* uno = fopen(argv[1], "r");
- FILE* due = fopen(argv[2], "r");
- FILE* tre = fopen(argv[3], "w");
+ if (atoi(argv[1]) == 1){
+ xor(argc, argv);
+ printf("Message successfully encrypted! \n");
+ } else if (atoi(argv[1]) == 2) {
+ printf("Working \n");
+ } else {
+ printf("WARNING no command specified!! \n");
+ help(argv);
+ fprintf(stderr,"Exiting... \n");
+ exit(EXIT_FAILURE);
+ }
+
+ exit(EXIT_SUCCESS);
+}
+
+void xor(int ac, char* av[]) {
+
+ int opt;
+ int defout = 0;
+ char* output;
+ while ((opt = getopt(ac, av, "o:")) != -1) {
+ switch (opt) {
+ case 'o':
+ output = av[(optind-1)];
+ defout = 1;
+ break;
+ default:
+ fprintf(stderr,"Usage %s %s [-o output] \n", av[0], av[1]);
+ exit(EXIT_FAILURE);
+ }
+ }
+
+ if (defout == 0) {
+ printf("WARNING no command specified using default value critt \n");
+ output = "critt";
+ }
+ FILE* mess_uno = fopen(av[2], "r");
+ FILE* mess_due = fopen(av[3], "r");
+ FILE* critt = fopen(output, "w");
int i = 1;
char a, b;
while(i != EOF) {
- i = fscanf(uno, "%c", &a);
- fscanf(due, "%c", &b);
+ i = fscanf(mess_uno, "%c", &a);
+ fscanf(mess_due, "%c", &b);
if(i != EOF) {
- fprintf(tre, "%c", a^b);
+ fprintf(critt, "%c", a^b);
}
}
- fclose(uno);
- fclose(due);
- fclose(tre);
+ fclose(mess_uno);
+ fclose(mess_due);
+ fclose(critt);
+
+ return;
+}
+
+void help(char* av[]) {
+ printf("ONETIMEBLUH USAGE: \n");
+ printf("%s [COMMAND] [OPTIONS] \n \n", av[0]);
+ printf("COMMANDS: \n");
+ printf("1 -> encrypt encrypt message (argv[1]) using key (argv[2]) \n");
+ printf("2 -> keygen create key file \n \n");
+ printf("OPTIONS \n");
+ printf("-b number of bytes \n");
+ printf("-o output name \n");
- return 0;
+ return;
}