Q:

C++ Program to Encrypt Files using File Handling

belongs to collection: C++ File Handling Solved Programs

0

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

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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 .

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C++ Program to Decrypt Files using File Handling... >>
<< C++ Program to Merge Two Files into a Single file...