In this program, we are going to share a C++ program to encrypt files. If you are a beginner and want to start learning the C++ programming, then keep your close attention in this tutorial as I am going to share a program for C++ program to encrypt files.
Copy the below C++ program and execute it with the help of GCC compiler. At the end of this program, We have shared the output of this program.
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 65 | #include<iostream.h> #include<conio.h> #include<fstream.h> #include<stdio.h> #include<stdlib.h> void main() { clrscr(); char fname[20], ch, choice; fstream fps, fpt; cout<<"Enter file name (with extension like file.txt) to encrypt : "; gets(fname); fps.open(fname); if(!fps) { cout<<"Error in opening file..!!"; cout<<"\nPress any key to exit..."; getch(); exit(1); } fpt.open("temp.txt") if(!fpt) { cout<<"Error in creating temp.txt file..!!"; fps.close(); cout<<"\nPress any key to exit..."; getch(); exit(2); } while(fps.eof()==0) { fps>>ch; ch=ch+100; fpt<<ch; } fps.close(); fpt.close(); fps.open(fname); if(!fps) { cout<<"Error in opening source file..!!"; cout<<"\nPress any key to exit..."; getch(); exit(3); } fpt.open("temp.txt"); if(!fpt) { cout<<"Error in opening temp.txt file...!!"; fps.close(); cout<<"\nPress any key to exit..."; getch(); exit(4); } while(fpt.eof()==0) { fpt>>ch; fps<<ch; } cout<<"File "<<fname<<" encrypted successfully..!!"; cout<<"\nPress any key to exit..."; fps.close(); fpt.close(); getch(); } |
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.