-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathencryption_process.c
More file actions
61 lines (48 loc) · 1.37 KB
/
Copy pathencryption_process.c
File metadata and controls
61 lines (48 loc) · 1.37 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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#define KEY 0xAA // encryption key
// XOR Encryption / Decryption
void encryptFile(const char *input, const char *output) {
FILE *fin = fopen(input, "rb");
FILE *fout = fopen(output, "wb");
if (!fin || !fout) {
printf("File error!\n");
exit(1);
}
char ch;
while ((ch = fgetc(fin)) != EOF) {
fputc(ch ^ KEY, fout);
}
fclose(fin);
fclose(fout);
}
// Random filename generator
void randomName(char *name) {
sprintf(name, "%c%c%d.enc",
'A' + rand() % 26,
'a' + rand() % 26,
rand() % 1000);
}
int main() {
char *files[3] = {"A.txt", "B.txt", "C.txt"}; //Files recieved from aditya
char encName[50];
FILE *map = fopen("map.txt", "w"); // saves encrypted file names and locations
if (!map) {
printf("Cannot create map file\n");
return 1;
}
srand(time(NULL));
// Step 1–4: Encrypt files & write map
for (int i = 0; i < 3; i++) {
randomName(encName);
encryptFile(files[i], encName);
fprintf(map, "%s|%s\n", files[i], encName);
}
fclose(map);
// Step 5: Encrypt map.txt
encryptFile("map.txt", "map.enc");
printf("PROCESS-1 completed successfully!\n");
return 0;
}