//Here i am making my own header file in which i declare all the header file which is used in this program and also declare the prototype of th function which i used in it.//
//BY using the include i am including my own header.h file in it I use "" over here to give its my own path instead if i give<> then it search on the specified 9 path which you will know if you want by giving the command on terminal echo$path//
#include"header.h"
//I made an another program.c file whose name is fun.c in which i define all the function which i used in my main program and call it throught my main program //
//same thing by using the include I include my whole file in it//
#include "fun.c"
int main()//from here my main fuction is starts//
{
//IN int declaration I declare the fd as the file descriptor of the file with which i can read or write it is the main file of which we can create a compressed file//
//fd1 is the file descriptor of the compressed file which is ompressed by using the compression technique.
///fd2 is the file descriptor of the encryption file in which our encrypted code is saved/
//cl is used to store the code length it tells upto what code length the file can be compressed.
//ndc is the total non descrimination character in the file which are used again and again in the file.//
//the count declared for the write and read function as it give the total character written in the file or we can say file chahracter length//
int fd=0,count=0,fd1=0,fd2=0,ndc=0,cl=0,fd3=0;
//In the char * ma the master array is stored which is further saved in encryption file we can also say it the encryption code of the file.//
char *ma;
//here i am calling the functipn openfile whose return value is an integer which i am storing in the fd as through openfile function it return me the fd of the file file which i opened here which is an integer hare i am catching that value in my fd as it is the main file which i have to compress most probably if i am opening first time a file the my fd is 3or any another greater than 3 because fd 0,1,2 are reserved for stdout, stdin and stderror//
fd=openfile();
printf("the fd=%d\n",fd);//used to print the fd of the file is to be compressed//
count=writefile(fd);//calling the write file function from the fun.c file inn which i described//
printf("the character written in the file is count=%d\n",count);//the total no. of char wriiten in file//
//After opening the file we made a stream in that in which we can read and write by using O_RDWR flag we already wrote in the file but as for the compression fist we made a master array in which we store all the non-descriptive no. which is not repeadted even no.//
ma=create_masterarray(fd,&ndc);
printf("the value of the ndc=%d\n",ndc);//the total length of the master array//
printf("master array is \n %s\n",ma);
//now we have to calculate the codelength to find the compression type by calling codelength we can find that//
cl=codelength(ndc);
printf(" the code length is cl=%d",cl);
//the compression() calling is over here by which we are making an compress file and returning the filedescriptor of it//
fd1=compression(fd,ma,ndc,cl);
printf(" the compressed file is made with the name compressed and the fdof that file is =%d\n",fd1);
//the encrypt ()is called over here which give us a code which we have to use for decompress the file without it we can't even decompress the file//
fd2=encrypt(ma,ndc);
printf(" the fd of the encrypt file is %d\n its string length is %d\n",fd2,ndc);
fd3=decompress(fd2,fd1);
return 0;
}
//#ifdef _HEADER.h
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<fcntl.h>
int openfile();
int writefile(int);
char* create_masterarray(int,int*);
int unique(char,char*,int);
int codelength(int);
int compression(int ,char *,int ,int);
int compress2(char *,int ,int);
int compress3(char *,int ,int);
int compress4(char *,int ,int);
int compress5(char *,int ,int);
int compress6(char *,int ,int);
int compress7(char *,int ,int);
int findloc(char,char*,int);
int encrypt(char* ,int);
int decompress (int,int);
//#endif
int decompress(int fde,int fdc)
{
int fd3;
int count ,size;
char ch ;
while(count)
{
count=read(fdc,&ch,1)
int encrypt(char *ma , int ndc)
{
int fd,count;
fd=open("encrypt file",O_CREAT|O_TRUNC|O_RDWR);
count=write(fd,ma,ndc);
printf("the characters written in the encryption_file is %d\n",count);
return fd;
}
int findloc(char ch ,char* ma ,int ndc)
{
int i;
for(i=0;i<ndc;i++)
{
if(ch==*(ma+i))
{
return i;
break;
}
}
return -1;
}
int compress4(char *ma,int fd,int ndc)
{
int fd1,loc;
char byt;
char byt1;
char byte,ch;
int count,countwrite;
lseek(fd,SEEK_SET,0);
fd1=open("compress",O_CREAT|O_RDWR|O_TRUNC);
while (count)
{
count=read(fd ,&ch,1);
loc=findloc(ch,ma,ndc);
byt=(char)loc;
byt=byt<<4;
byt=byt>>4;
count=read(fd ,&ch,1);
loc=findloc(ch,ma,ndc);
byt1=(char)loc;
byt1=byt1<<4;
byte=byte^byte;
byte=byt|byt1;
countwrite=write(fd1,&byte,1);
}
return fd1;
}
int compression(int fd ,char *ma,int ndc,int cl)
{
int fd1;
switch(cl)
{
case 2:
//fd1=compress2(ma,fd,ndc);
break;
case 3:
//fd1=compress3(ma,fd,ndc);
break;
case 4:
fd1=compress4(ma,fd,ndc);
break;
case 5:
//fd1=compress5(ma,fd,ndc);
break;
case 6:
//fd1=compress6(ma,fd,ndc);
break;
case 7:
//fd1=compress7(ma,fd,ndc);
break;
default :
printf("the file is not going to be compressed");
break;
}
return fd1;
}
int codelength(int ndc)
{
int i,cl=1;
for(i=0;cl<=ndc;i++)
cl=cl*2;
return i;
}
int unique(char ch,char *ma,int ndc)
{
int i;
for(i=0;i<ndc;i++)
{
if(*(ma+i)==ch)
It looks like you're new here. If you want to get involved, click one of these buttons!