Good day.

I am attempting to write a C++ Program than must open a text file
with random caharacters and then convert these characters into readble text. It must also be able to do the reverse

Example like:

If the text file has "%&^#)@!#@"
It should convert that into
"Hello how are you"
I thought of using a kind of find and replace command.
just not sure what i can use. It can just be a plain simple console app.

#include <iostream >
#include <windows.h>
using std :: cout;
using std :: endl;
void encrypt( char [ ] ); // prototypes of functions used in the code
void decrypt( char * ePtr );
int main( )
{
// create a string to encrypt
char string[ ] = "this is a secret!";
cout << "Original string is: " << string << endl;
encrypt( string );
// call to the function encrypt( )
cout << "Encrypted string is: " << string << endl;
decrypt( string );
// call to the function decrypt( )
cout << "Decrypted string is: " << string << endl;
return 0;
}// main

//encrypt data
void encrypt (char e[] ) 
{
for( int i=0; e[i] != '\0'; ++i ) ++e[i];
} // encrypt
//decrypt data
void decrypt( char * ePtr ) {
for( ; * ePtr != '\0'; ++ ePtr ) --(* ePtr);
system("pause");
}

I didn't got you completely. Why to use Find and replace?

For Encryption :
Open the file, read the lines in a string, call encrypt and then store back.
For Decryption :
Open the file, read the lines in a string, call decrypt and then store back.

Is that what you want?

This article has been dead for over six months. Start a new discussion instead.