-
Notifications
You must be signed in to change notification settings - Fork 1
/
xorfiles.c
36 lines (29 loc) · 915 Bytes
/
xorfiles.c
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
#include <stdio.h>
#include <stdint.h>
void main(int argc, char* argv[]) {
if(argc < 4) {
printf("Usage: %s <source1> <source2> <destination>\n", argv[0]);
return;
}
FILE* qcrypt_input1;
FILE* qcrypt_input2;
FILE* qcrypt_output;
if((qcrypt_input1 = fopen(argv[1], "r")) == NULL) {
printf("couldn't open first source %s for writing\n", argv[1]);
return;
}
if((qcrypt_input2 = fopen(argv[2], "r")) == NULL) {
printf("couldn't open second source %s for writing\n", argv[2]);
return;
}
if((qcrypt_output = fopen(argv[3], "w")) == NULL) {
printf("couldn't open destination %s for writing\n", argv[3]);
return;
}
int c1, c2;
char xored;
while((c1 = fgetc(qcrypt_input1)) != EOF && (c2 = fgetc(qcrypt_input2)) != EOF) {
xored = c1 ^ c2;
fputc(xored, qcrypt_output);
}
}