-
Notifications
You must be signed in to change notification settings - Fork 0
/
decompression2.c
executable file
·114 lines (89 loc) · 2.37 KB
/
decompression2.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
// this is decompression of 2 bytei
#include"header.h"
#include"prototype.h"
int decompression2(char *open_encr,char *open_key,char *str)
{
//printf("in function----->%s\n",__func__);
unsigned char *buff=NULL,ch,d,c,e,f;
unsigned int efd,efd2,fd2,fd3,i=0,count,count1,length,j,n,r;
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;
// count = count-1;
while(i<length)
{
r =read(fd2,&ch,1);
if(r=1)
{
// printf("character is read......yeah!----->%c && %d\n",ch,ch);
c = ch;
d = ch;
e = ch;
f = ch;
c = c >> 6;
d = d << 2;
d = d >> 6;
e = e << 4;
e = e >> 6;
f = f << 6;
f = f >> 6;
}
// else
// printf("character is not readed from file....oops!!\n");
if(j<count)
{
// printf("the locationn is ------>%d\n",c);
write(fd3,(buff+c),1);
// printf("the written charracter is %c\n",*(buff+c));
// printf("the no. of characters had witten---->%d\n",j);
j++;
}
if(j<count)
{
// printf("the location is -------->%d\n",d);
write(fd3,(buff+d),1);
// printf("the written character is %c\n",*(buff+d));
// printf("the no. of characters had witten---->%d\n",j);
j++;
}
if(j<count)
{
// printf("the locationn is ------>%d\n",e);
write(fd3,(buff+e),1);
// printf("the written charracter is %c\n",*(buff+e));
// printf("the no. of characters had witten---->%d\n",j);
j++;
}
if(j<count)
{
// printf("the location is -------->%d\n",f);
write(fd3,(buff+f),1);
// printf("the written character is %c\n",*(buff+f));
// printf("the no. of characters had witten---->%d\n",j);
j++;
}
i++;
}
close(fd2);
close(fd3);
close(efd);
return 0;
}