Sie sind auf Seite 1von 7

/*

Written By : Saurabh Jain I Year B.sc (Hons) Computer Science College Of Vocational Studies Delhi University

This Program Will Encrypt Or Decrypt Ant Text Document Its A Complete Bug Free Program If Modified Please Send To : sid_isin@yahoo.com */ /* This Program Will Encrypt Any Type Of Text Document */ #include<fstream.h> #include<conio.h> #include<stdio.h> int main() { char name[30],target[30],ch,mod; Variables int num[100],i,option; cout<<"Enter Your Option "; cout<<" 1. To Encrypt The File "; cout<<" 2. To Decrypt The File "; cout<<" Option : "; cin>>option; if(option==1) { cout<<"Enter The Path Of A File Which Is To Be Encrypted : "; gets(name); ifstream fin(name,ios::binary); Input File In A Binary Mode if(!fin) { Error Occur If File Does Not Exist cout<<" Error In Openinig Of A File : "; Error Occurs return 1; } cout<<" Enter The New Encrypted File Name : "; gets(target); //Open The //Show

//Declare

//Or Any

ofstream fout(target,ios::binary); OutPut File In A Binary Mode if(!fout) { cout<<" Error In Opening Of Target File : "; If Any Error Occrs In Opening Of A File return 1; } for(i=0;i<9;i++) { For Loops For Storing The Numbers num[i]=i; Array } for(i=14;i<31;i++) Store 100 Numbers { num[i-5]=i; Encrypt The Contents Of A File } for(i=33;i<=68;i++) The Error Ocuur Caused By The { , Tab Key & Space Key num[i-7]=i; Variations In Loops Is Made } for(i=97;i<=122;i++) { num[i-35]=i; } while(fin) { Input File fin.get(ch); if(ch==EOF)break; When End Of File if((ch>=97) && (ch<=122)) { Small Letters i=97; mod=num[ch-i]; fout<<mod; } if((ch>=65) && (ch<=90))

//Open The

//Show Error

//Multiple //In An

//Loops Will //Which Will

//To Avoid //Enter Key //These

//Open The

//Exit To Loop

//Encrypt The

{ i=39; Capital Letters mod=num[ch-i]; An Output File fout<<mod; } if((ch>=48) && (ch<=57)) { i=4; Numbers mod=num[ch+i]; fout<<mod; } if((ch==10) (ch==13)) { mod=ch; fout<<mod; } if(ch==32) fout<<ch; if(ch==9) fout<<ch; if((ch>=33)&&(ch<=47)) { Symbols mod=ch+64; fout<<mod; } if((ch>=58)&&(ch<=64)) { Symbols mod=ch+54; fout<<mod; } if((ch>=91)&&(ch<=96)) { mod=ch+28; Symbols fout<<mod; } if((ch>=123)&&(ch<=126)) { mod=ch-40; Symbols fout<<mod; } } fin.close(); File //Encrypt The //And Store In

//Encrypt The

//For Enter Key

//For Space Key //For Tab Key //For Special

//For Special

//For Special

//For Special

//Close The Input

fout.close(); Output File cout<<" Your File Is Encrypted Now........... "; getch(); return 0; }

//Close The

/*======================================================================== =======================================*/ /* This Program Will Decrypt The Document */ if(option==2) { char name[30],target[30],ch,mod; Variables int num[100],i,flag;

//Declare

cout<<"Enter The Path Of A File Name Which Is To Be Decrypted : "; gets(name); ifstream fin(name,ios::binary); if(!fin) Encryped File In A Binary Mode { cout<<"Error In Opening Of A File : "; return 1; Error If File Does Not Exist } Occurs In Opening Of A File cout<<" Enter The New Decrypted File Name : "; gets(target); ofstream fout; fout.open(target,ios::binary); Output File In An Binary Mode if(!fout) { Error If Any Error Occurs In Opening Of A File cout<<"Error In Opening Of A Target File : "; return 1; } for(i=0;i<9;i++) { Multiple For Loops For Storing The Numbers num[i]=i; Array //Opens The //Show //Open The

//Show //Or Any

//Same //In An

} for(i=14;i<31;i++) { num[i-5]=i; Will Store 100 Numbers } for(i=33;i<=68;i++) Encrypts The Document Also Decrypt It { num[i-7]=i; } while(fin) { Encryped File fin.get(ch); flag=0; Off Flag if(ch==EOF)break; for(i=26;i<52;i++) { if(ch==num[i]) Match The Small Letters Letters { mod=i+39; Then Put Appropriate Letter fout<<mod; File flag=1; break ; Flag And Exit The Loop } } if (flag==1) continue ; Flag Is On Then Continue Outer Loop for(i=0;i<26;i++) { Match The Capital Letters if(ch==num[i]) { Then Put Appropriate Letter mod=i+97; File fout<<mod; flag=1;break; Flag And Exit From This Loop } } if (flag==1) continue ;

//Loops

//Which

//Opens The //Turn

//Loop For //If Match //In A OutPut //Turn On

//If

//Loop For //If Match //In A OutPut //Turn On

//If Flag

Is On Then Continue Outer Loop for(i=52;i<62;i++) { Numerical Numbers if(ch==num[i]) { mod=i-4; fout<<mod; flag=1; break ; } } if (flag==1) continue ; if((ch==10) (ch==13)) { mod=ch; Enter Key fout<<mod; } if(ch==32) fout<<ch; Space Key if(ch==9) fout<<ch; Tab Key if((ch>=97)&&(ch<=111)) { mod=ch-64; Symbols fout<<mod; } if((ch>=112)&&(ch<=118)) { mod=ch-54; Symbols fout<<mod; } if((ch>=119)&&(ch<=124)) { mod=ch-28; Symbols fout<<mod; } if((ch>=83)&&(ch<=86)) { Symbols mod=ch+40; fout<<mod; } //Loop For

//Condition For

//Condition For

//Condition For

//For Special

//For Special

//For Special

//For Special

} fin.close(); Encrypted File fout.close(); Original Decrypted File cout<<" The File Is Being Decrypted............ "; getch(); return 0; } return 0; } //Close The //Close Your

Das könnte Ihnen auch gefallen