Encrypt / Decrypt Text File

How would one go about encrypting and decrypting a text file?
Open a stream for reading, read the file content into string, encrypt the string and write the string back. Same process for decrypting.
This might help:
http://www.cplusplus.com/forum/windows/128374/
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>
#include <fstream>
#include <iterator>
#include <algorithm>
using namespace std;

using it = istream_iterator<char>;
using ot = ostream_iterator<char>;

char encrypt( char c ) { return c + 1; }         // I'm sure that you can do something more exciting
char decrypt( char c ) { return c - 1; }         // Ditto

int main ()
{
   ifstream in ( "infile.txt"  );   it initer ( in  );
   ofstream out( "outfile.txt" );   ot outiter( out );
   transform( initer, {}, outiter, encrypt );
}
Registered users can post here. Sign in or register to post.