-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsplitter.c
76 lines (64 loc) · 1.6 KB
/
splitter.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
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>
void encrypt_data(FILE* input_file, FILE* output_file, char* key)
{
int key_count = 0;
int encrypt_byte;
while( (encrypt_byte = fgetc(input_file)) != EOF)
{
fputc(encrypt_byte ^ *(key+key_count), output_file);
key_count++;
if(key_count == strlen(key))
key_count = 0;
}
}
void writefile(FILE* input_file,FILE *output_file,int size)
{
int i = 0 ;
int encrypt_byte;
encrypt_byte = fgetc(input_file);
while((i<=size||size==-1) && encrypt_byte!=EOF)
{
fputc(encrypt_byte , output_file);
encrypt_byte = fgetc(input_file);
i++;
}
}
int main()
{
FILE *old,*new,*new1,*one,*two;
int sz;
char *key="password12345";
old = fopen("database.txt","r");
new = fopen("database_enc.txt","w");
encrypt_data(old,new,key);
fclose(old);
fclose(new);
new = fopen("database_enc.txt","r");
new1=fopen("database_enc.txt","r");
one=fopen("one.txt","w");
two=fopen("two.txt","w");
fseek(new,0,SEEK_END);
sz = ftell(new);
printf("sz is %d\n",sz);
fseek(new,0,SEEK_SET);
writefile(new,one,sz/2);
fseek(new1,sz/2+1, SEEK_SET);
writefile(new1,two,sz-(sz/2));
fclose(new);
fclose(new1);
fclose(one);
fclose(two);
//joing the file to orginal file
one=fopen("one.txt","r");
two=fopen("two.txt","r");
old=fopen("database_join.txt","w");
writefile(one,old,-1);
writefile(two,old,-1);
fclose(one);
fclose(two);
fclose(old);
old=fopen("database_join.txt","r");
new=fopen("database_final.txt","w");
encrypt_data(old,new,key);
return 0;
}