-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfileEncryptor.c
More file actions
80 lines (59 loc) · 1.97 KB
/
fileEncryptor.c
File metadata and controls
80 lines (59 loc) · 1.97 KB
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
77
78
79
80
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdlib.h>
#include "caesar.c"
#include "vigenere.c"
typedef enum algo {
caesar,
vigenere
}Algo;
int main(int argc, char **argv) {
char* filePath;
char* key;
bool decypher = false;
Algo algo = caesar; // Default
for (int i = 1; i < argc; i++) {
if (strcmp(argv[i], "-h") == 0) {
// Open file in read mode
FILE *fptr = fopen("help.txt", "r");
// Check if the file was opened successfully
if (fptr == NULL) {
return 1;
}
// Read and print each character from the file
char ch;
while ((ch = fgetc(fptr)) != EOF) {
putchar(ch);
}
// Close the file after reading
fclose(fptr);
return 0;
} else if ((strcmp(argv[i], "-f") == 0 | strcmp(argv[i], "--file") == 0) && i + 1 < argc) {
i++;
filePath = (char*)malloc(strlen(argv[i]));
strcpy(filePath, argv[i]);
} else if ((strcmp(argv[i], "-k") == 0 | strcmp(argv[i], "--key") == 0) && i + 1 < argc) {
i++;
key = (char*)malloc(strlen(argv[i]));
strcpy(key, argv[i]);
} else if (strcmp(argv[i], "-d") == 0 | strcmp(argv[i], "--decipher") == 0) {
decypher = true;
} else if (strcmp(argv[i], "-c") == 0 | strcmp(argv[i], "--caesar") == 0) {
algo = caesar;
} else if (strcmp(argv[i], "-v") == 0 | strcmp(argv[i], "--vigenere") == 0) {
algo = vigenere;
}
}
printf("Algo : %d \r\n", algo);
printf("Decypher : %d \r\n", decypher);
printf("FilePath : %s \r\n", filePath);
switch (algo) {
case caesar :
caesarCypher(filePath, key, decypher);
break;
case vigenere :
vigenereAlgo(filePath, key, decypher);
break;
}
}