Skip to content

Commit ab36f83

Browse files
committed
7-Bit Deompression done!
1 parent 7905b36 commit ab36f83

File tree

1 file changed

+191
-0
lines changed

1 file changed

+191
-0
lines changed

decompression7.c

Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
// this is decompression of 5 byte
2+
#include"header.h"
3+
#include"prototype.h"
4+
int decompression7(char *open_encr,char *open_key,char *str)
5+
{
6+
7+
// printf("in function----->%s\n",__func__);
8+
9+
unsigned char *buff=NULL,ch,d,c,e,f,m;
10+
unsigned int efd,efd2,fd2,fd3,i=0,count,count1,length,j,n,r;
11+
12+
char decr1[]=".decompressed";
13+
14+
char *decr;
15+
16+
decr=malloc(strlen(str) + strlen(decr1) + 1);
17+
18+
19+
strcpy(decr, str);
20+
strcat(decr, decr1);
21+
printf("decompressed file name is---> %s\n",decr);
22+
efd=open(open_key,O_RDONLY);
23+
efd2=open(str,O_RDONLY);
24+
fd2=open(open_encr,O_RDONLY);
25+
fd3=open(decr,O_WRONLY | O_CREAT);
26+
27+
28+
count=lseek(efd2,0,SEEK_END);
29+
count1=lseek(efd,0,SEEK_END); //master array
30+
length=lseek(fd2,0,SEEK_END); //encrypted file
31+
lseek(efd2,0,SEEK_SET);
32+
lseek(efd,0,SEEK_SET);
33+
lseek(fd2,0,SEEK_SET);
34+
// printf("no. of characters in actual file && encrypted file is : %d && %d\n",count,length);
35+
buff=(char*)malloc(sizeof(char)*(count1));
36+
37+
count1=read(efd,buff,(count1));
38+
// printf("master array is : %s\n and no. of characters-----: %d\n",buff,count1);
39+
j=1,f=0;
40+
while(i<length)
41+
{
42+
43+
r =read(fd2,&ch,1);
44+
if(f==0)
45+
{
46+
// printf("in ---->f(0)\n");
47+
// printf("character is read......yeah!----->%c && %d\n",ch,ch);
48+
c = ch;
49+
d = ch;
50+
c = c >> 1;
51+
if(j<count)
52+
{
53+
write(fd3,(buff+c),1);
54+
// printf("the written charracter is %c\n",*(buff+c));
55+
j++;
56+
}
57+
58+
59+
}
60+
if(f==1)
61+
{
62+
// printf("in ---->f(1)\n");
63+
// printf("character is read......yeah!----->%c && %d\n",ch,ch);
64+
c = ch;
65+
e = ch;
66+
d = d << 7;
67+
d = d >> 1;
68+
c = c >> 2;
69+
d = d | c;
70+
71+
if(j<count)
72+
{
73+
write(fd3,(buff+d),1);
74+
// printf("the written charracter is %c\n",*(buff+d));
75+
j++;
76+
}
77+
78+
79+
}
80+
if(f==2)
81+
{
82+
83+
// printf("in ---->f(2)\n");
84+
c = ch;
85+
d = ch;
86+
e = e << 6;
87+
e = e >> 1;
88+
c = c >> 3;
89+
c = c | e;
90+
if(j<count)
91+
{
92+
write(fd3,(buff+c),1);
93+
// printf("the written charracter is %c\n",*(buff+c));
94+
j++;
95+
}
96+
97+
}
98+
if(f==3)
99+
{
100+
// printf("in ---->f(3)\n");
101+
// printf("character is read......yeah!----->%c && %d\n",ch,ch);
102+
c = ch;
103+
e = ch;
104+
d = d << 5;
105+
d = d >> 1;
106+
c = c >> 4;
107+
d = d | c;
108+
109+
110+
if(j<count)
111+
{
112+
write(fd3,(buff+d),1);
113+
// printf("the written charracter is %c\n",*(buff+d));
114+
j++;
115+
}
116+
117+
}
118+
if(f==4)
119+
{
120+
// printf("in ---->f(4)\n");
121+
// printf("character is read......yeah!----->%c && %d\n",ch,ch);
122+
c = ch;
123+
d = ch;
124+
e = e << 4;
125+
e = e >> 1;
126+
c = c >> 5;
127+
c = c | e;
128+
if(j<count)
129+
{
130+
write(fd3,(buff+c),1);
131+
// printf("the written charracter is %c\n",*(buff+c));
132+
j++;
133+
}
134+
135+
}
136+
if(f==5)
137+
{
138+
// printf("in ---->f(5)\n");
139+
c = ch;
140+
e = ch;
141+
d = d << 3;
142+
d = d >> 1;
143+
c = c >> 6;
144+
d = d | c;
145+
if(j<count)
146+
{
147+
write(fd3,(buff+d),1);
148+
// printf("the written charracter is %c\n",*(buff+d));
149+
j++;
150+
}
151+
152+
}
153+
if(f==6)
154+
{
155+
// printf("in ---->f(6)\n");
156+
// printf("character is read......yeah!----->%c && %d\n",ch,ch);
157+
c = ch;
158+
m = ch;
159+
e = e << 2;
160+
e = e >> 1;
161+
c = c >> 7;
162+
c = c | e;
163+
m = m << 1;
164+
m = m >> 1;
165+
if(j<count)
166+
{
167+
write(fd3,(buff+c),1);
168+
// printf("the written charracter is %c\n",*(buff+c));
169+
j++;
170+
}
171+
if(j<count)
172+
{
173+
write(fd3,(buff+m),1);
174+
// printf("the written charracter is %c\n",*(buff+m));
175+
j++;
176+
}
177+
178+
179+
}
180+
i++;
181+
f++;
182+
if(f==7)
183+
f=0;
184+
}
185+
close(fd2);
186+
close(fd3);
187+
close(efd);
188+
return 0;
189+
190+
}
191+

0 commit comments

Comments
 (0)