Encrypting & Decrypting Strings in C++

Here is code to encrypt a String and then Decrypt it.

Code :

#include <iostream>
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);
}

Output : 

Original string is: this is a secret!
Encrypted string is: uijt!jt!b!tfdsfu"
Decrypted string is: this is a secret!

Comments