-
Notifications
You must be signed in to change notification settings - Fork 0
/
decompression4.c
executable file
·64 lines (56 loc) · 1.6 KB
/
decompression4.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
// this is decompression ofi 4 byte
#include"header.h"
#include"prototype.h"
int decompression4(char *open_encr,char *open_key,char *str)
{
char decr1[]=".decompressed";
char *decr;
decr=malloc(strlen(str) + strlen(decr1) + 10);
strcpy(decr, str);
strcat(decr, decr1);
printf("decompressed file name is---> %s\n",decr);
// printf("in function----->%s\n",__func__);
unsigned char *buff=NULL,ch,c,d;
unsigned int efd,fd2,fd3,i=0,count,count1,length,j,n,r;
efd=open(open_key,O_RDONLY);
// printf("efd is : %d\n",efd);
count=lseek(efd,0,SEEK_END);
// printf("count is : %d\n",count);
buff=(char*)malloc(sizeof(char)*(count));
lseek(efd,0,SEEK_SET);
count1=read(efd,buff,(count));
// printf("master array is : %s\n and count1: %d\n",buff,count1);
fd2=open(open_encr,O_RDONLY);
if(fd2!=0)
printf("ENCRYPTED FILE IS OPENED\n");
fd3=open(decr,O_RDWR | O_CREAT);
if(fd3!=0)
{
printf("main file is opened\n");
}
length=lseek(fd2,0,SEEK_END);
// printf("the total characters in actuall file------>%d \n",length);
lseek(fd2,0,SEEK_SET);
for(i=0;i<=(length-1);i++)
{
r =read(fd2,&ch,1);
if(r!=1)
// printf("character is not read......oops!!\n");
c = ch;
d = ch;
c = c >> 4;
d = d << 4;
d = d >> 4;
// printf("the locationn is ------>%d\n",c);
write(fd3,(buff+c),1);
// printf("the written charracter is %c\n",*(buff+c));
// sprintf(&n,"%d",d);
// printf("the location is -------->%d\n",d);
write(fd3,(buff+d),1);
// printf("the written character is %c\n",*(buff+d));
}
close(fd2);
close(fd3);
close(efd);
return 0;
}