summaryrefslogtreecommitdiffstats
path: root/onetimebluh.c
blob: 83cf93a72d2c2dc79228745e3eded32ad06611a2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#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[]) {
	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;
	char* defname = "critt";
	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 = defname;
	}
	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(mess_uno, "%c", &a);
		fscanf(mess_due, "%c", &b);
		if(i != EOF) {
			fprintf(critt, "%c", a^b);
		}
	}
	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;
}