-
Notifications
You must be signed in to change notification settings - Fork 0
/
decompression6.c
executable file
·122 lines (100 loc) · 2.34 KB
/
decompression6.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// this is decompression of 3 byte
#include"header.h"
#include"prototype.h"
int decompression6(char *open_encr,char *open_key,char *str)
{
// printf("in function----->%s\n",__func__);
unsigned char *buff=NULL,ch,d,c,e,f,m;
unsigned int efd,efd2,fd2,fd3,i=0,count,count1,length,j,n,r;
printf("encryption file name is---> %s\n",open_encr);
printf("kry file name is---> %s\n",open_key);
char decr1[]=".decompressed";
char *decr;
decr=malloc(strlen(str) + strlen(decr1) + 1);
strcpy(decr, str);
strcat(decr, decr1);
printf("decompressed file name is---> %s\n",decr);
efd=open(open_key,O_RDONLY);
efd2=open(str,O_RDONLY);
fd2=open(open_encr,O_RDONLY);
fd3=open(decr,O_WRONLY | O_CREAT);
count=lseek(efd2,0,SEEK_END);
count1=lseek(efd,0,SEEK_END); //master array
length=lseek(fd2,0,SEEK_END); //encrypted file
lseek(efd2,0,SEEK_SET);
lseek(efd,0,SEEK_SET);
lseek(fd2,0,SEEK_SET);
// printf("no. of characters in actual file && encrypted file is : %d && %d\n",count,length);
buff=(char*)malloc(sizeof(char)*(count1));
count1=read(efd,buff,(count1));
// printf("master array is : %s\n and no. of characters-----: %d\n",buff,count1);
j=1,f=0;
while(i<length)
{
r =read(fd2,&ch,1);
if(f==0)
{
// printf("in ---->f(0)\n");
// printf("character is read......yeah!----->%c && %d\n",ch,ch);
c = ch;
d = ch;
c = c >> 2;
if(j<count)
{
write(fd3,(buff+c),1);
// printf("the written charracter is %c\n",*(buff+c));
j++;
}
}
if(f==1)
{
// printf("in ---->f(1)\n");
// printf("character is read......yeah!----->%c && %d\n",ch,ch);
c = ch;
m = ch;
d = d << 6;
d = d >> 2;
m = m >> 4;
d = d | m;
if(j<count)
{
write(fd3,(buff+d),1);
// printf("the written charracter is %c\n",*(buff+d));
j++;
}
}
if(f==2)
{
// printf("in ---->f(1)\n");
// printf("character is read......yeah!----->%c && %d\n",ch,ch);
m = ch;
d = ch;
c = c << 4;
c = c >> 2;
d = d >> 6;
c = c | d;
m = m << 2;
m = m >> 2;
if(j<count)
{
write(fd3,(buff+c),1);
// printf("the written charracter is %c\n",*(buff+c));
j++;
}
if(j<count)
{
write(fd3,(buff+m),1);
// printf("the written charracter is %c\n",*(buff+m));
j++;
}
}
i++;
f++;
if(f==3)
f=0;
}
close(fd2);
close(fd3);
close(efd);
return 0;
}