-
Notifications
You must be signed in to change notification settings - Fork 0
/
decompression3.c,v
166 lines (147 loc) · 2.84 KB
/
decompression3.c,v
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
head 1.1;
access;
symbols;
locks
root:1.1; strict;
comment @ * @;
1.1
date 2017.11.13.17.04.17; author root; state Exp;
branches;
next ;
desc
@this is 3-bit decompression file
@
1.1
log
@Initial revision
@
text
@// this is decompression of 3 byte
#include"header.h"
#include"prototype.h"
int decompression3()
{
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;
efd=open("compression",O_RDONLY);
efd2=open("ranjan",O_RDONLY);
fd2=open("encrypted_file",O_RDONLY);
fd3=open("compressed_file",O_RDWR);
count=lseek(efd2,0,SEEK_END); //main file nikhil
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;
e = ch;
c = c >> 5;
d = d << 3;
d = d >> 5;
e = e << 6;
e = e >> 5;
if(j<count)
{
write(fd3,(buff+c),1);
printf("the written charracter is %c\n",*(buff+c));
j++;
}
if(j<count)
{
write(fd3,(buff+d),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;
d = ch;
m = ch;
c = c >>7;
e = e | c;
c = ch;
c = c << 1;
c = c >> 5;
d = d << 4;
d = d >> 5;
m = m << 7;
m = m >> 5;
if(j<count)
{
write(fd3,(buff+e),1);
printf("the written charracter is %c\n",*(buff+e));
j++;
}
if(j<count)
{
write(fd3,(buff+c),1);
printf("the written charracter is %c\n",*(buff+c));
j++;
}
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);
c = ch;
d = ch;
e = ch;
c = c >> 6;
m = m | c;
d = d << 2;
d = d >> 5;
e = e << 5;
e = e >> 5;
if(j<count)
{
write(fd3,(buff+m),1);
printf("the written charracter is %c\n",*(buff+m));
j++;
}
if(j<count)
{
write(fd3,(buff+d),1);
printf("the written charracter is %c\n",*(buff+d));
j++;
}
if(j<count)
{
write(fd3,(buff+e),1);
printf("the written charracter is %c\n",*(buff+e));
j++;
}
}
i++;
f++;
if(f==3)
f=0;
}
close(fd2);
close(fd3);
close(efd);
return 0;
}
@