You are on page 1of 33

AMBEDKAR INSTITUTE OF TECHNOLOGY

(Guru Gobind Singh Indraprastha University)

SUMMER INTERNSHIP REPORT


Undertaken at

EmbLogic Embedded Technologies Pvt. Ltd.


IN
EMBEDDED LINUX with ARM

PROJECT MULTIPLE DATA COMPRESSION AND ENCRYPTION USING ITERATIVE METHOD

SUBMITTED IN PARTIAL FULFILLMENT OF THE DEGREE OF BACHELOR OF TECHNOLOGY IN ELECTRONICS AND COMMUNICATION ENGINEERING

AMBEDKAR INSTITUTE OF TECHNOLOGY, GGSIPU Summer Training after second Year Year-2011

Under the guidance of: Mr. Siddharth (tutor) EmbLogic Embedded Technologies Pvt. Ltd.

ACKNOWLEDGEMENT
I hereby take this opportunity to thank all those people whose knowledge and experience helped me bring this report in its present form. It would have been a tough task for me to complete report without their help. I express my sincere thanks and gratitude to My tutor Mr. Siddharth, EmbLogic Embedded Technologies Pvt. Ltd. for providing me the opportunity to pursue my training at the institute. I would like to express my gratitude to my group member, Miss. Kiran for helping me in every aspect during the training phase as well as in carrying out the whole project. Finally I would like to express my deep appreciation to my family and friends who have been a constant source of inspiration. I am internally grateful to them for always encouraging me wherever and whenever I needed them.

Hemkaran Singh Raghav 04210102909

INSTITUTE PROFILE
ABOUT EMBLOGIC
EmbLogic is a technology design, integration and devices Realization Company, providing out of the box solutions and end to end embedded solutions for product development and deployment. It offers professional design services like hardware and software development, customizable product designs, Systems Engineering and COTS Solutions that improve quality and accelerate time-to-market for a broad range of embedded systems. Through technological innovations, quality and timely deliveries, It work to ensure increased values and optimized throughput for the customers. Its solutions ensure customers sustain their competitive edge and added value and volumes to their business. It aspire to serve the industry through training, development and consulting. A career at EmbLogic comes with opportunities for continuous learning coupled with professional challenges that highlight individual performance. We consistently believed in and practiced openness, transparency and equal opportunity.

ACTIVITIES
EmbLogic offers out of the box solutions customized for various segments. Our expertise lies in designing, realizing and deploying customized solutions that integrate multi-vendor Commercial Off The Shelf Solutions, custom device design including software and hardware design. The system engineering process involves:
o o o o

Identifying sourcing devices products and accessories Design procure and realize hardware sub-systems Developing system software System integration

Emblogic helps customers and developers save valuable time as it could be a single source of hardware and software solutions. We provide expert design support and development services. Our Services include: o o o o o o o o o o o Hardware Board Design Reference Designs Board Bring-up, Diagnostic Package Development Boot Loader Development/ RTOS Board Support Packages Development for SoC Modules Driver Development Firmware Development Protocol Stack and Middleware Development Embedded Applications Codec Integration Verification and Validation Services for embedded devices

Design Realization EmbLogic offers product realization services from idea-tosolution, concept-to-deployment covering various aspects of conceptualization, architecture, device design, planning implementation, development, application development, porting and enhancement.

ABOUT EMBEDDED LINUX WITH ARM Objective This course is designed to ensure that students of Engineering College with academic capabilities will have the skill set needed to deal with the challenges involved in real-world embedded technologies to meet the needs of industries both today and in the future. The course considers programming techniques which can help to ensure that single-processor embedded systems are reliable. The course is taught mainly using the C programming language, with a ARM Board and PC emulated as an embedded device. Introduction Embedded Linux is the use of Linux in embedded computer systems such as mobile phones, personal digital assistants, media players, set-top boxes, and other consumer electronics devices, networking equipment, machine control, industrial automation, navigation equipment and medical instruments. According to survey conducted by Venture Development Corporation, Linux was used by 18% of embedded engineers. Linux is the version of Linux running on processors with a Memory Management Unit (MMU). Processors without MMU can run a modified version of Linux called uClinux. The uClinux tab provides pre-built uClinux images for specific ARM processors Key benefits of Linux on ARM

Complete scalable operating system providing a reliable multitasking environment Based on an open source model (GPL) Leverage a wide range of UNIX and open source applications Early availability on ARM processor-based platforms Used in many ARM technology-based designs including networking and wireless space Broad support through open discussion forums

The course is split into Six modules:


Data Structures with C Shell Scripts Linux Internals and System Programming Linux Device Drivers Embedded & Network Protocols Embedded Linux with ARM

The Duration of the Training is:

60 Sessions of 2 hrs each (About 1.5 years). (In 6 weeks training, I have covered the top three modules of the training.)

LINUX
Linux is a Unix-like computer operating system assembled under the model of free and open source software development and distribution. The defining component of any Linux system is the Linux kernel, an operating system kernel first released October 5, 1991 by Linus Torvalds. Linux system distributions may vary in many details of system operation, configuration, and software package selections. Linux runs on a wide variety of computer hardware, including mobile phones, tablet computers, network routers, televisions, video game consoles, desktop computers, mainframes and supercomputers. Linux is a leading server operating system, and runs the 10 fastest supercomputers in the world. In addition, more than 90% of today's supercomputers run some variant of Linux. Most Linux distributions support dozens of programming languages. The original development tools used for building both Linux applications and operating system programs are found within the GNU toolchain, which includes the GNU Compiler Collection (GCC) and the GNU build system. Amongst others, GCC provides compilers for Ada, C, C++, Java, and Fortran. The whole Linux kernel is written in C language.

C with DATA STRUCTURES


C is a general-purpose computer programming language developed in 1972 by Dennis at the Bell Telephone Laboratories for use with the UNIX operating system. Although C was designed for implementing system software, it is also widely used for developing portable application software. It is one of the most popular programming languages and there are very few computer architectures for which a C compiler does not exist. C has greatly influenced many other popular programming languages, most notably C++, which originally began as an extension to C. Objective This short course is designed to ensure that we, the students of Engineering College with academic Capabilities will have the skill set needed to deal with the challenges involved in real-world Programming using c, Advanced C or System C, to meet the needs of industries both today and in the future. The course is taught mainly using the GCC compiler, with Linux operating system. In this course, following contents are taught:

Introduction and Programming Strategies o Features of C language, Broad structure of C. o Understanding C syntax, Data types, Escape sequences. o Operators, C conventions, Error Handling. o Some Programming Language Notes. Structured Programming Strategies o Decision Making and Looping Decision Structures Looping Structures. Break and Continue statements. o Functions Function prototypes, function calling, function body, Arguments, by value and by Reference, Steps Involved In invoking a function, Recursive Functions, Types of functions, Functions Returning Pointers.

Arrays, Structures and Unions Definition of Arrays, Comparison between arrays and pointers, Single Dimension Array, Two Dimensional Arrays, Structures & Unions, Memory layout, Bit fields in structure, functions and structures o Pointers Declaration of pointers, Rules valid for pointers, Pointer usage, Pointers, addressing, referencing and dereferencing, Passing pointers to a function, Strings with Pointers. o String IO Accessing individual characters, Printing strings with printf, Printing strings with puts, Inputting strings with scanf, Inputting strings with gets, String Library (strcpy(), strcat(), strcmp(), strchr(), strstr(), spintf(), sscanf(), atoi()). o Memory Allocation Overview of memory management, Allocating new heap memory, _ Deallocating heap memory, Checking for successful memory allocation, Memory errors, Using memory you dont own, Faulty heap management. o Operation in C Files, File naming, Opening a file, Writing and reading a file, Character input and output, Direct file input and output operations, Closing and flushing of files, Sequential and random files. Data Structures o Array and pointer: Array creation, Array notation (pointer, direct etc), Review of pointer fundamentals, Review of Pointer operations, Parameter passing as pointers. o Sorting and searching methods Various sorting techniques, Bubble sort, Merge sort, Quick sort, various search techniques: Sequential search, Binary search, Radix search. o Stack and queue Stack Fundamentals, Stack implementation, Queue Fundamentals, Queue Implementation. o Linked list Fundamentals Link list basics, Elementary link list functions. o Linked list Advanced Reversing link list (different methods), by swapping, By recursion, Doubly link list, Basics of doubly link list, Circular link list.

SHELL SCRIPTING
A shell script is a script written for the shell, or command line interpreter, of an operating system. It is often considered a simple domain-specific programming language. Typical operations performed by shell scripts include file manipulation, program execution, and printing text. Many shell script interpreters double as command line interface, such as the various Unix shells, C Shell and bash shell etc. In their most basic form, a shell script can provide a convenient variation of a system command where special environment settings, command options, or post processing is applied automatically, but in a way that allows the new script to still act as a fully normal LINUX command. Objective This short course is designed to ensure that we, the students of Engineering College with academic capabilities will have the skill set needed to deal with the challenges involved in real-world Scripting to meet the needs of industries both today and in the future. Contents:

Introduction to shells and scripts: o Shells, Usage, Types, entering and editing commands, Shell scripts, tools for editing, writing scripts. Running and Controlling Scripts: o Referencing variables, loops and iterations, conditionals, if, test, case, examining environment variables, customizing accounts, handling CLI, executing. Shell Scripting Functions: o Defining and Using Functions, arguments, return codes, variable scope, and global, local recursion. Debugging Shell Scripts: o Deciphering Error Messages, Debugging Techniques and Running Scripts in Debugging Mode.

LINUX INTERNELS AND SYSTEM PROGRAMMING


This is advanced/internals-based knowledge required for the true understanding of the advanced topics and supporting a UNIX or Linux system. It consists, how the internals of the operating system hangs together - it is intended to assist with the administration of the operating system itself and the theory can be applied to both the UNIX and the Linux operating systems. Linux is a freely distributed implementation of UNIX-like kernel, low-level core of an operating system. All programs written for UNIX can be compiled and run on Linux. Linux applications are represented by two special types of files: executable and scripts. Executable files are programs that can be run directly by the compiler; they correspond to windows .exe files. Scripts are collections of instructions for another program, an interpreter, to follow. There correspond to Windows .bat or .cmd files, or interpreted BASIC programs. Linux does not require executables or scripts to have a specific filename or any extension whatsoever. File system attributes, are used to indicate that a file is a program that may be run. In linux, we can replace scripts with compiled programs without affecting other programs, is comes under the system programming in which user prepares software for system or kernel of operating systems. Objective This short course is designed to ensure that we, the students of Engineering College with academic Capabilities will have the skill set needed to deal with the challenges involved in real-world Programming to meet the needs of industries both today and in the future. The course is taught mainly using the gcc compiler, with Linux operating system.

Course Contents:

Introduction to Linux and Terminals Development Tools in Linux Process Management: Duplicating Processes, Replacing Processes. Signals and Handlers Inter-Process Communication: Pipes and FIFOs Synchronization Techniques Inter-Process Communication: Message Queues & Shared Memory Communication Endpoints : Sockets POSIX Threads

PROJECT MULTIPLE DATA COMPRESSION AND ENCRYPTION USING ITERATIVE METHOD Description :
It is a C program developed for COMPRESSION & ENCRYPTION of a text file. Whole code is written in C language (GNU standard) using GCC compiler in LINUX environment. It should required to work on Terminal (Linux based Shell) for invoking this project. Scope: Scope of this project is in the field of communication where the same information can be transmitted in less number of Bytes as compared to original text. Since the information is also in the encrypted format so no one can understand the actual information contained in the text. So it has many application in the Military Forces where information should be secured also in the transmission from one site to another.

How to invoke :
For invoking this project we required the executable file of this project only. NO need of whole C program. I have named the compiled code as compress which is a executable file. You should run this file in terminal as: $ ./compress <your file name>

It will compress and also encrypt your file. The new compressed file named as <your file name>.7zip Now if we want to decompress this file on another location or site we should required again only the executable code compress only. We can decompress and de-encrypt our compressed file named as <your file name>.7zip just by writing in terminal as: $ ./compress <your file name>.7zip -d (here we need to pass an argument -d for decompressing it.)

Mutliple compression:
By the use of multiple compression, we can compress our file to many levels (limited). We can compress our pre-compressed file to another level. The new file will get another .7zip extension. Means number of times .7zip extension tells you the level of compression. --> <your file name>.7zip.7zip (contains two level of compression) But you can compress under a certain limit because after a certain limit the compressed file size can be more than the normal file size. For example: Open the terminal. $ cd compress_project $ ls

(nik is a text file to compress)

Compiled the code for generating executable file.

$ vi nik (show the content of nik)

$ ./compress nik

(compress and encrypt the file)

$ vi nik.7zip

(file is compressed and in the encrypted format as shown) $ ./compress nik.7zip (Multiple compression)

Decompressing the file using an argument -d.

Showing the content of decompressed file (hemnew) as: $ vi hemnew

(It is the new file generated contains the original information as in the file nik ).

SOURCE CODE
#include<stdio.h> #include<stdlib.h> #include<string.h> char *compress_name; /**************Function declarations**************/ void compress2(unsigned char*,int); void compress3(unsigned char*,int); void compress4(unsigned char*,int); void compress5(unsigned char*,int); void compress6(unsigned char*,int); void compress7(unsigned char*,int); void decompress2(unsigned char*,char*); void decompress3(unsigned char*,char*); void decompress4(unsigned char*,char*); void decompress5(unsigned char*,char*); void decompress6(unsigned char*,char*); void decompress7(unsigned char*,char*); /****************start of Main********************/ int main(int argc, char* argv[]) { char *p,*m,*m1,*ar,*co,ch; int i,j,l1,l,l2,k,flag,*as; FILE *fd,*f,*fopen(); int SIZE; SIZE=0; if(argv[2]==NULL) { fd= fopen(argv[1],"r"); if(fd==NULL) { printf("error : No such file or directory.\n"); exit(EXIT_FAILURE); } while((ch=getc(fd))!=EOF) { SIZE++; } m=malloc(sizeof(char)*127); //master array p=malloc(sizeof(char)*SIZE); //main string ar=malloc(sizeof(char)*SIZE); i=0; fclose(fd); fd=fopen(argv[1],"r"); while((ch=getc(fd))!=EOF) {

*(p+i)=ch; i++; } i--; l=strlen(p); compress_name=malloc(sizeof(char)*50); compress_name=argv[1]; strcat(compress_name,".7zip"); /****************************Generating master array*****************/ for(i=0,j=0;i<l;i++) { flag=0; for(k=0;k<j;k++) { if(*(p+i)==*(m+k)) { flag=1; break; } } if(flag==0) { *(m+j)=*(p+i); j++; } } l1=strlen(m); //length of master array char lm; lm=(char)l1; f=fopen(compress_name,"w"); putc(lm,f); for(i=0;i<l1;i++) { putc(*(m+i),f); } fclose(f); /**************generating original array with ASCII values**************/ for(i=0;i<l;i++) { for(j=0;j<l1;j++) { if(*(m+j)==*(p+i)) *(ar+i)=j+1; } } fclose(fd);

/****************************calling of function*******************/ if(l1>=2 && l1<=4) compress2(ar,l-1); if(l1>=5 && l1<=8) compress3(ar,l-1); if(l1>=9 && l1<=16) compress4(ar,l-1); if(l1>=17 && l1<=32) compress5(ar,l-1); if(l1>=33 && l1<=64) compress6(ar,l-1); if(l1>=65 && l1<=128) compress7(ar,l-1); if(l1>128) printf("Hey you, file should be in ASCII characters\n"); printf("File compressed successfully with the extension of .7zip...\n"); } /**********************Reading of file for decompression**************/ else { FILE *fd1,*fopen(); char lm2; fd1=fopen(argv[1],"r"); if(fd1==NULL) { printf("error : No such file or directory.\n"); exit(EXIT_FAILURE); } SIZE=0; while((ch=getc(fd1))!=EOF) { SIZE++; } fclose(fd1); co=malloc(sizeof(char)*SIZE); m1=malloc(sizeof(char)*127); i=0; fd1=fopen(argv[1],"r"); lm2=getc(fd1); for(i=0;i<lm2;i++) { ch=getc(fd1); *(m1+i)=ch; } *(m1+i)='\0'; i=0; while((ch=getc(fd1))!=EOF)

{ *(co+i)=ch; i++; } i--; fclose(fd1); /**************************Decompression***********************/ if(lm2>=2 && lm2<=4) decompress2(co,m1); if(lm2>=5 && lm2<=8) decompress3(co,m1); if(lm2>=9 && lm2<=16) decompress4(co,m1); if(lm2>=17 && lm2<=32) decompress5(co,m1); if(lm2>=33 && lm2<=64) decompress6(co,m1); if(lm2>=65 && lm2<=128) decompress7(co,m1); if(lm2>128) printf("Hey you, file should be in ASCII characters\n"); printf("File decompressed successfully.\n File name is : hemnew\n"); } return 0; } //end of main /***********************compression functions***************************/ void compress2(unsigned char *temp,int len) { int i; FILE *f,*fopen(); f = fopen(compress_name,"a"); for(i=0;i<len;i=i+4) //performing compression { unsigned char a,b,c,d,e; d=*(temp+i)<<6; c=(*(temp+i+1)<<4)&(48); b=(*(temp+i+2)<<2)&(12); a=(*(temp+i+3))&(3); e=a|b|c|d; putc(e,f); } fclose(f); } //put e(ORed result) to f file

void compress3(unsigned char *temp,int len) { FILE *f,*fopen(); f=fopen(compress_name,"a"); int i; unsigned char c; for(i=0;i<len;i+=7) { c=((*(temp+i)<<5)&(224))|((*(temp+i+1)<<2)&(28))|((*(temp+i+2) >>1)&(3)); putc(c,f); c=((*(temp+i+2)<<7)&(128))|((*(temp+i+3)<<4)&(112))|((*(temp+i +4)<<1)&(14))|((*(temp+i+5)>>2)&(1)); putc(c,f); c=((*(temp+i+5)<<6)&(192))|((*(temp+i+6)<<3)&(56)); putc(c,f); } fclose(f); } void compress4(unsigned char *temp,int len) { int i; unsigned char c; FILE *f,*fopen(); f=fopen(compress_name,"a"); for(i=0;i<len;i+=2) { c=((*(temp+i)<<4)&(240))|(*(temp+i+1)&(15)); putc(c,f); } fclose(f); } void compress5(unsigned char *temp,int len) { int i; unsigned char c; FILE *f,*fopen(); f=fopen(compress_name,"a"); for(i=0;i<len;i=i+8) { c=(*(temp+i)<<3)|((*(temp+i+1)>>2)&7); putc(c,f); c=((*(temp+i+1)<<6))|((*(temp+i+2)<<1)&62)|((*(temp+i+3)> >4)&1); putc(c,f); c=((*(temp+i+3)<<4))|((*(temp+i+4)>>1)&15); putc(c,f);

c=((*(temp+i+4)<<7))|((*(temp+i+5)<<2)&124)|((*(temp+i+6) >>3)&3); putc(c,f); c=((*(temp+i+6)<<5))|((*(temp+i+7)&31)); putc(c,f); } fclose(f); } void compress6(unsigned char *temp,int len) { int i; unsigned char c,d,e; FILE *f,*fopen(); f=fopen(compress_name,"a"); for (i=0;i<len;i+=4) { c= ((*(temp+i)<<2)&(252)|(*(temp+i+3))&(3)); putc(c,f); d=((*(temp+i+1)<<2)&(252)|(*(temp+i+3)>>2)&(3)); putc(d,f); e=((*(temp+i+2)<<2)&(252)|(*(temp+i+3)>>4)&(3)); putc(e,f); } fclose(f); } void compress7(unsigned char *temp,int len) { int i; unsigned char c; FILE *f,*fopen(); f=fopen(compress_name,"a"); for(i=0;i<len;i+=8) { c= ((*(temp+i)<<1)&(254)|(*(temp+i+7)>>6)&(1)); putc(c,f); c= ((*(temp+i+1)<<1)&(254)|(*(temp+i+7)>>5)&(1)); putc(c,f); c= ((*(temp+i+2)<<1)&(254)|(*(temp+i+7)>>4)&(1)); putc(c,f); c= ((*(temp+i+3)<<1)&(254)|(*(temp+i+7)>>3)&(1)); putc(c,f); c= ((*(temp+i+4)<<1)&(254)|(*(temp+i+7)>>2)&(1)); putc(c,f); c= ((*(temp+i+5)<<1)&(254)|(*(temp+i+7)>>1)&(1)); putc(c,f); c= ((*(temp+i+6)<<1)&(254)|(*(temp+i+7))&(1)); putc(c,f);

} fclose(f); } /************************Decompression function**********************/ void decompress2(unsigned char *temp,char *m) { int l,l1,i,j; unsigned char ch; l=strlen(temp); l1=strlen(m); FILE *f,*fopen(); f=fopen("hemnew","w"); for(i=0;i<l;i++) { ch=*(temp+i)>>6; for(j=0;j<l1;j++) { if(ch==(j+1)) { putc(*(m+j),f); break; } } ch=(*(temp+i)>>4)&(3); for(j=0;j<l1;j++) { if(ch==(j+1)) { putc(*(m+j),f); break; } } ch=(*(temp+i)>>2)&(3); for(j=0;j<l1;j++) { if(ch==(j+1)) { putc(*(m+j),f); break; } } ch=*(temp+i)&(3); for(j=0;j<l1;j++) { if(ch==(j+1)) { putc(*(m+j),f); break; } } }

fclose(f); } void decompress3(unsigned char *temp,char *m) { int l,l1,i,j; unsigned char ch; l=strlen(temp); l1=strlen(m); FILE *f,*fopen(); f=fopen("hemnew","w"); for(i=0;i<l;i+=3) { ch=*(temp+i)>>5; for(j=0;j<l1;j++) { if(ch==(j+1)) { putc(*(m+j),f); break; } } ch=(*(temp+i)>>2)&(7); for(j=0;j<l1;j++) { if(ch==(j+1)) { putc(*(m+j),f); break; } } ch= (*(temp+i)<<1)&(6)|(*(temp+i+1)>>7)&(1); for(j=0;j<l1;j++) { if(ch==(j+1)) { putc(*(m+j),f); break; } } ch=(*(temp+i+1)>>4)&(7); for(j=0;j<l1;j++) { if(ch==(j+1)) { putc(*(m+j),f); break; } } ch=(*(temp+i+1)>>1)&(7); for(j=0;j<l1;j++) { if(ch==(j+1))

{ } }

putc(*(m+j),f); break;

ch=(*(temp+i+1)<<2)&(4)|(*(temp+i+2)>>6)&(3); for(j=0;j<l1;j++) { if(ch==(j+1)) { putc(*(m+j),f); break; } }

ch=(*(temp+i+2)>>3)&(7); for(j=0;j<l1;j++) { if(ch==(j+1)) { putc(*(m+j),f); break; } } ch= *(temp+i+2)&(7); for(j=0;j<l1;j++) { if(ch==(j+1)) { putc(*(m+j),f); break; } } } fclose(f); } void decompress4(unsigned char *temp,char *m) { int l,l1,i,j; unsigned char ch; l=strlen(temp); l1=strlen(m); FILE *f,*fopen(); f=fopen("hemnew","w"); for(i=0;i<l;i++) { ch=(*(temp+i)>>4)&(15); for(j=0;j<l1;j++) { if(ch==(j+1)) { putc(*(m+j),f); break;

} } ch=*(temp+i)&(15); for(j=0;j<l1;j++) { if(ch==(j+1)) { putc(*(m+j),f); break; } } } fclose(f); } void decompress5(unsigned char *temp,char *m) { int l,l1,i,j; unsigned char ch; l=strlen(temp); l1=strlen(m); FILE *f,*fopen(); f=fopen("hemnew","w"); for(i=0;i<l;i+=5) { ch=(*(temp+i)>>3); for(j=0;j<l1;j++) { if(ch==(j+1)) { putc(*(m+j),f); break; } } ch=((*(temp+i)&7)<<2)|((*(temp+i+1)>>6)); for(j=0;j<l1;j++) { if(ch==(j+1)) { putc(*(m+j),f); break; } } ch=(*(temp+i+1)>>1)&(31); for(j=0;j<l1;j++) { if(ch==(j+1)) { putc(*(m+j),f); break; } }

ch=(*(temp+i+1)<<4)&(16)|((*(temp+i+2)>>4)); for(j=0;j<l1;j++) { if(ch==(j+1)) { putc(*(m+j),f); break; } } ch=((*(temp+i+2)<<1)&(31))|(*(temp+i+3)>>7); for(j=0;j<l1;j++) { if(ch==(j+1)) { putc(*(m+j),f); break; } } ch=((*(temp+i+3)>>2)&(31)); for(j=0;j<l1;j++) { if(ch==(j+1)) { putc(*(m+j),f); break; } } ch=((*(temp+i+3)<<3)&(31))|((*(temp+i+4)>>5)); for(j=0;j<l1;j++) { if(ch==(j+1)) { putc(*(m+j),f); break; } } ch=((*(temp+i+4)&(31))); for(j=0;j<l1;j++) { if(ch==(j+1)) { putc(*(m+j),f); break; } } } fclose(f); } void decompress6(unsigned char *temp,char *m) { int l,l1,i,j; unsigned char ch; l=strlen(temp);

l1=strlen(m); FILE *f,*fopen(); f=fopen("hemnew","w"); for(i=0;i<l;i+=3) { ch=*(temp+i)>>2; for(j=0;j<l1;j++) { if(ch==(j+1)) { putc(*(m+j),f); break; } } ch =*(temp+i+1)>>2; for(j=0;j<l1;j++) { if(ch==(j+1)) { putc(*(m+j),f); break; } } ch=*(temp+i+2)>>2; for(j=0;j<l1;j++) { if(ch==(j+1)) { putc(*(m+j),f); break; } } ch=(*(temp+i)&(3))|(*(temp+i+1)<<2)&(12)|(*(temp+i+2)<<4)&(48); for(j=0;j<l1;j++) { if(ch==(j+1)) { putc(*(m+j),f); break; } } } fclose(f); } void decompress7(unsigned char *temp,char *m) { int l,l1,i,j; unsigned char ch; l=strlen(temp); l1=strlen(m); FILE *f,*fopen(); f=fopen("hemnew","w");

for(i=0;i<l;i+=7) { ch=*(temp+i)>>1; for(j=0;j<l1;j++) { if(ch==(j+1)) { putc(*(m+j),f); break; } } ch=*(temp+i+1)>>1; for(j=0;j<l1;j++) { if(ch==(j+1)) { putc(*(m+j),f); break; } } ch= *(temp+i+2)>>1; for(j=0;j<l1;j++) { if(ch==(j+1)) { putc(*(m+j),f); break; } } ch=*(temp+i+3)>>1; for(j=0;j<l1;j++) { if(ch==(j+1)) { putc(*(m+j),f); break; } } ch=*(temp+i+4)>>1; for(j=0;j<l1;j++) { if(ch==(j+1)) { putc(*(m+j),f); break; } } ch=*(temp+i+5)>>1; for(j=0;j<l1;j++) { if(ch==(j+1)) { putc(*(m+j),f); break; } }

ch=*(temp+i+6)>>1; for(j=0;j<l1;j++) { if(ch==(j+1)) { putc(*(m+j),f); break; } } ch=(*(temp+i)<<6)&(64)|(*(temp+i+1)<<5)&(32)|(*(temp+i+2)<<4)&(16)|( *(temp+i+3)<<3)&(8)|(*(temp+i+4)<<2)&(4)|(*(temp+i+5)<<1)&(2)|(*(temp+i+6) &(1)); for(j=0;j<l1;j++) { if(ch==(j+1)) { putc(*(m+j),f); break; } } } fclose(f); } //*****************End of decompressing functions***************//

You might also like