C++ Program to Encrypt Files using File Handling

By | 05.01.2017

Encrypt Files using File Handling


Write a C++ Program to Encrypt Files using File Handling. Here’s simple Program to Encrypt Files using File Handling in C++ Programming Language.


Below is the source code for C++ Program to Encrypt Files using File Handling which is successfully compiled and run on Windows System to produce desired output as shown below :


SOURCE CODE : :


/*  C++ Program to Encrypt Files using File Handling  */

#include<iostream>
#include<fstream>
#include<stdio.h>
#include<stdlib.h>
using namespace std;

int main()
{

        char fname[20], ch, choice;
        fstream fps, fpt;
        cout<<"Enter file name to encrypt :: ";
        cin>>fname;

        fps.open(fname);

        if(!fps)
        {
                cout<<"\nError in opening file..!!";
                cout<<"\nPress any key to exit...";

                exit(1);
        }

        fpt.open("C:\\Users\\acer\\Documents\\file5.txt");
        if(!fpt)
        {
                cout<<"\nError in creating file5.txt file..!!";
                fps.close();
                cout<<"\nPress any key to exit...";

                exit(2);
        }
        while(fps.eof()==0)
        {
                fps>>ch;
                ch=ch+100;
                fpt<<ch;
        }

        fps.close();
        fpt.close();
        fps.open(fname);
        if(!fps)
        {
                cout<<"\nError in opening source file..!!";
                cout<<"\nPress any key to exit...";

                exit(3);
        }
        fpt.open("C:\\Users\\acer\\Documents\\file5.txt");
        if(!fpt)
        {
                cout<<"\nError in opening temp.txt file...!!";
                fps.close();
                cout<<"\nPress any key to exit...";

                exit(4);
        }
        while(fpt.eof()==0)
        {
                fpt>>ch;
                fps<<ch;
        }
        cout<<"\nFile "<<fname<<" encrypted successfully..!!";
        cout<<"\n\nPress any key to exit...";
        fps.close();
        fpt.close();
        return 0;
}

OUTPUT : :


/*  C++ Program to Encrypt Files using File Handling  */

Enter file name to encrypt :: C:\\Users\\acer\\Documents\\file4.txt

File C:\\Users\\acer\\Documents\\file4.txt encrypted successfully..!!

Press any key to exit...

Process returned 0

Above is the source code for Write a C++ Program to Encrypt Files using File Handling which is successfully compiled and run on Windows System.The Output of the program is shown above .

If you found any error or any queries related to the above program or any questions or reviews , you wanna to ask from us ,you may Contact Us through our contact Page or you can also comment below in the comment section.We will try our best to reach up to you in short interval.


Thanks for reading the post….

5 2 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments