Add to Favorites    Make Home Page 2473 Online  
 Language Categories  
 Our Services  

Home » C Home » Beginners / Lab Assignments Home » Encryption and Decryption of file wat so ever

A D V E R T I S E M E N T

Search Projects & Source Codes:

Title Encryption and Decryption of file wat so ever
Author Rahul
Author Email rahul_aurora_it [at] yahoo.co.in
Description The following C code can encrypt any sort of file be it be a sound,image,video or etc

Category C » Beginners / Lab Assignments
Hits 382437
Code Select and Copy the Code
/* A simulated C program to encrypt or decrypt a file with L=26, K=3 and Buffer Stream Divisions=2 as per described approach */ /* Few Notations used R-Read W-write */ #include<stdio.h> #include<conio.h> #include<process.h> #include"fcntl.h" #include"types.h" #include"stat.h" #include<io.h> #include<ctype.h> #include<time.h> #include<stdlib.h> /*Procedure to copy a buffer stream content to another unsigned char *strcp(unsigned char buf[],unsigned char l[],unsigned int byt) { for(int i=0;i<byt;i++) buf[i]=l[i]; buf[i]=0; return(buf); } /*Procedure To reverse buffer stream content*/ unsigned char *strrever(unsigned char buf[],unsigned int byt) { unsigned char l[1024]; for(int i=byt-1;i>=0;i--) l[i]=buf[i]; l[i]=0; for(i=0;i<byt;i++) buf[i]=l[i]; buf[i]=0; return(buf); } /* Procedure Jumble Buffer stream content*/ unsigned char *strjab(unsigned char buf[],unsigned int byt,unsigned char parts,unsigned char comb) { unsigned char k[1024],l[1024],x[1024],y[1024]; int hlen,i,j,len,n=0; if(parts==2&&comb==2) { len=byt; hlen=len/2; for(i=0;i<hlen;i++) k[i]=buf[i]; k[i]=0; j=i; for(i=hlen;i<len;i++) {l[n]=buf[i];n++;} l[n]=0; for(i=0;i<j;i++) l[n+i]=k[i]; l[n+i]=0; for(i=0;i<len;i++) buf[i]=l[i]; buf[i]=0; } else if(parts==4) { } strrever(buf,byt); return(buf); } /* A procedure to Encrypt a given file of any format taking parameter name of the as parameter. */ int encrypt(unsigned char *p) { unsigned char buf[1024]; // buf is a buffer where data of file is R/W int in,out,i; /* 'in' is a handle to a file which is for R a file 'out' is a handle to a file which is for W a file, 'i' is a counter */ unsigned int byt; z:in=open(p,O_RDONLY|O_BINARY); // Opening given file in R mode out=open("�",O_CREAT|O_BINARY|O_WRONLY,S_IWRITE); // Opening a temp file in W mode if(in==-1) { return(0); // if file doesn't exist it quits } while(1) { byt=read(in,buf,1024); /* The os starts fetching data from the file and fills it in the buffer*/ for(i=0;i<byt;i++) // looping the buffer { _BL=buf[i]; asm neg bl; _CL=0x04; asm ror bl,cl; _BL=_BL+0x1B0; buf[i]=_BL; /* Encryption logic is applied and a single byte is encrypted */ asm xor bl,bl; } if(byt>0) // If file is not empty it goes to next statement { write(out,buf,byt); // The buffer values are written in temp file } else // If file is now empty then it is quits the loop break; } close(in); // Closing the given file close(out); // Closing the temp file in=open("�",O_RDONLY|O_BINARY); // Opening Temp file in R mode out=open(p,O_CREAT|O_BINARY|O_WRONLY,S_IWRITE); // Opening given file in W mode if(in==-1) //If resource file gets deleted by an attack by an other process { close(in); close(out); // The process restarts goto z; } while(1) { byt=read(in,buf,1024); // R content of Temp file strjab(buf,byt,2,2); if(byt>0) write(out,buf,byt); // W content to Given file else break; } close(in); // Closing the Temp file close(out); // Closing the Given file remove("�"); // Deleting the temp file strcp(buf," "); //Corrupting the present Buffer value return(1); } /* A procedure to Decrypt a given file of any format taking parameter name of the as parameter. */ int decrypt(unsigned char *p) { unsigned char buf[1024]; // buf is a buffer where data of file is R/W int in,out,i; /* 'in' is a handle to a file which is for R a file 'out' is a handle to a file which is for W a file, 'i' is a counter */ unsigned int byt; l:in=open(p,O_RDONLY|O_BINARY); // Opening given file in R mode out=open("�",O_CREAT|O_BINARY|O_WRONLY,S_IWRITE); // Opening a temp file in W mode if(in==-1) // if file doesn't exist it quits { return(0); } while(1) { byt=read(in,buf,1024); // R content of Given file for(i=0;i < byt;i++) { _BL=buf[i]; _BL=_BL-0x1B0; _CL=0x04; asm rol bl,cl; // Decrypting logic for Decrypting a Single byte asm neg bl; buf[i]=_BL; asm xor bl,bl; } if(byt>0) { write(out,buf,byt); //W into Temp file } else break; } close(in); close(out); in=open("�",O_RDONLY|O_BINARY); // Opening Temp file in R mode out=open(p,O_CREAT|O_BINARY|O_WRONLY,S_IWRITE); // Opening Given file in W mode if(in==-1) { close(in); close(out); goto l; } while(1) { byt=read(in,buf,1024); strjab(buf,byt,2,2); //Jumbling the buffer stream if(byt>0) write(out,buf,byt); // W into Given file else break; } close(in); close(out); remove("�"); // Deleting Temp file strcp(buf," "); // Corrupting the buffer return(1); } /* The Main Function to execute the program */ int main(int argc,char *argv[]) { clock_t start, end; argc=argc&argc; argc=14; if(strcmp(argv[1],"")==0) //If No File or No Input is specified { clrscr(); textcolor(14); // User Help Screen when no input is dragged cprintf(" DRAG AN INPUT FILE TOWARDS THIS ICON"); textcolor(RED); cputs(" DO LOCKING OR UNLOCKING BY TYPING L OR U"); textcolor(GREEN); cputs(" IF U FRIST LOCK A FILE THEN UNLOCK IT FOR RETRIEVAL AND VICE-VERSA"); _setcursortype(_NOCURSOR); getch(); return(0); } else { char c; clrscr(); // User input Screen if they drag a file x:printf(" U WANT LOCK OR UNLOCK THE FILE (L/U):"); /* If u press L or l for the first time, then for retrieval press U or u and vice versa.. The if u r were pressing L or l for 'N' times without pressing U or u then for retrieval pressing U or u 'N' times */ _setcursortype(_SOLIDCURSOR); c=getchar(); //Giving the input whether to lock or unlock by pressing 'L' or 'U' (or) 'l' or 'u' if(c=='L' || c=='l') //Procedure for locking { printf(" Locking...."); _setcursortype(_NOCURSOR); start = clock(); //Starting the clock counter encrypt(argv[1]); end = clock(); // Stopping the clock counter printf(" The time was: %f ", (end - start) / CLK_TCK); } else if(c=='U' || c=='u') //Procedure for unlocking { printf(" Unlocking....."); _setcursortype(_NOCURSOR); start=clock(); //Starting the clock counter decrypt(argv[1]); end= clock(); // Stopping the clock counter printf(" The time was: %f ",(end - start) / CLK_TCK); } else { printf(" wrong i/p,please press a key as per given i/p's "); _setcursortype(_NOCURSOR); getch(); clrscr(); goto x; } } return(1); }

Related Source Codes

Script Name Author
The Game Opposite as seen on Nokia 2300 Mobile Manikanta
RECURSIVE BALANCED QUICK SORT ashish
Radix Sort ashish
Change your mouse pointer Ashim
The blinking star Shashank
Data Validation Crylittlebaby
To search a file by giving file type like mp3 or mpeg or doc Prashanth SR
Menus Demonstration B.Chidhambaram
Employee Database Project Using C. Reenku Raman Nayak
Creating a Lexical Analyzer in c fahad bader al-buhairi �դ ?�� ��??���
Calendar Program Omkar & Devendra
Stop double Process for start in C Cedrik Jurak
Stop double Process for start in C Cedrik Jurak
Time Scheduler Atiq Anwar
A timepass game between atmost two players Rahul Roy

A D V E R T I S E M E N T




Google Groups Subscribe to SourceCodesWorld - Techies Talk
Email:

Free eBook - Interview Questions: Get over 1,000 Interview Questions in an eBook for free when you join JobsAssist. Just click on the button below to join JobsAssist and you will immediately receive the Free eBook with thousands of Interview Questions in an ebook when you join.

New! Click here to Add your Code!


ASP Home | C Home | C++ Home | COBOL Home | Java Home | Pascal Home
Source Codes Home Page

 Advertisements  

Google Search

Google

Source Codes World.com is a part of Vyom Network.

Vyom Network : Web Hosting | Dedicated Server | Free SMS, GRE, GMAT, MBA | Online Exams | Freshers Jobs | Software Downloads | Interview Questions | Jobs, Discussions | Placement Papers | Free eBooks | Free eBooks | Free Business Info | Interview Questions | Free Tutorials | Arabic, French, German | IAS Preparation | Jokes, Songs, Fun | Free Classifieds | Free Recipes | Free Downloads | Bangalore Info | Tech Solutions | Project Outsourcing, Web Hosting | GATE Preparation | MBA Preparation | SAP Info | Software Testing | Google Logo Maker | Freshers Jobs

Sitemap | Privacy Policy | Terms and Conditions | Important Websites
Copyright ©2003-2024 SourceCodesWorld.com, All Rights Reserved.
Page URL: http://www.sourcecodesworld.com/source/show.asp?ScriptID=929


Download Yahoo Messenger | Placement Papers | Free SMS | C Interview Questions | C++ Interview Questions | Quick2Host Review