E ncryption: Write a program in Python or C++ that has TWO functions: Function O
ID: 655344 • Letter: E
Question
Encryption:
Write a program in Python or C++ that has TWO functions:
Function One is called: _encrypt
Function Two is called: _decrypt
Function one takes plain text, and assesses the indexed value of each letter in the string. For example, a=1, b=2. It then adds three to the indexed value, and produces encrypted text, based off of the plain text.
Function two reverses this.
Here is sample output:
_encrypt('how do you do')
Unsecured: howdoyoudo
Secured: lsahscsyhs
_decrypt('lsahscsyhs')
Unsecured: lsahscsyhs
Secured: howdoyoudo
Explanation / Answer
#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[ ] = "how do you do";
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] != ''; ++i ) ++e[i];
} // encrypt
//decrypt data
void decrypt( char * ePtr ) {
for( ; * ePtr != ''; ++* ePtr ) --(* ePtr);
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.