Question

In: Computer Science

I need to complete this C++ program. The instructions are in the comments inside the code...

I need to complete this C++ program. The instructions are in the comments inside the code below:

-------------------------------------------------------------------------

Original string is: this is a secret!

Encypted string is: uijt!jt!b!tfdsfu"

Decrypted string is: this is a secret!

//Encoding program

//Pre-_____?

//other necessary stuff here

int main()

{

//create a string to encrypt using a char array

cout<< "Original string is: "<<string<<endl;

encrypt(string);

cout<< "Encrypted string is: "<<string<<endl;

decrypt(string);

cout<<"Decrypted string is: "<<string<<endl;

return 0;

}

void encrypt(char e[])

{

//Write implementation function encrypt

}

void decrypt(char *ePtr)

{

//Write implementation function decrypt

}

Solutions

Expert Solution

Original string is: this is a secret!

Encypted string is: uijt!jt!b!tfdsfu"

Decrypted string is: this is a secret!

Here we can observe that Substitution encryption technique has been used with key as 1. So a will be repcaed with b b with c and so on. Here each character in plain text will be replaced by its next character in ascii table.

#include <iostream>
using namespace std;

void encrypt(char e[]);
void decrypt(char *ePtr);

int main()

{

//create a string to encrypt using a char array
char string[100]="this is a secret!";

cout<< "Original string is: "<<string<<endl;

encrypt(string);

cout<< "Encrypted string is: "<<string<<endl;

decrypt(string);

cout<<"Decrypted string is: "<<string<<endl;

return 0;

}

void encrypt(char e[])

{

//Write implementation function encrypt
int i=0;
while(e[i]!='\0')
{
e[i]=(char)(((int)e[i]+1)%128);
i=i+1;
}

}

void decrypt(char *ePtr)

{

//Write implementation function decrypt
while(*ePtr!='\0')
{
*ePtr=(char)(((int)*ePtr+127)%128);
ePtr++;
}

}


Related Solutions

Please complete the following code in C using the comments as instructions. Further instructions are below...
Please complete the following code in C using the comments as instructions. Further instructions are below the code. challenge.c // goal: print the environment variables to the file "env.txt", one per line // (If envp is NULL, the file should be empty, opening in write mode will do that.) // example: // inputs: // envp/environ = {"E1=2","E2=7",NULL} // outputs: // env.txt as a string would be "E1=2\nE2=7\n" // example: // inputs: // envp/environ = {NULL} or NULL // outputs: //...
Complete the program used on the instructions given in the comments: C++ lang #include <string> #include...
Complete the program used on the instructions given in the comments: C++ lang #include <string> #include <vector> #include <iostream> #include <fstream> using namespace std; vector<float>GetTheVector(); void main() { vector<int> V; V = GetTheVector(); //reads some lost numbers from the file “data.txt" and places it in //the Vector V Vector<int>W = getAverageOfEveryTwo(V); int printTheNumberOfValues(W) //This should print the number of divisible values by 7 //but not divisible by 3. PrintIntoFile(W); //This prints the values of vector W into an output file...
i need C++ program with possible comments what is going on,(a) Write a program that reads...
i need C++ program with possible comments what is going on,(a) Write a program that reads a char as input, and determines if it is a lowercase letter, uppercase letter, a digit or something else (call the last one a special character).
I need the c# code for the below assignment. Complete PigLatin program in Windows Forms GUI....
I need the c# code for the below assignment. Complete PigLatin program in Windows Forms GUI. Zip the solution project file and attach to this submission. Do this in the GUI format (Windows Form). Be sure and add a Clear Button to reset for entering another word or words. PigLatinGUI Basic Steps in Creating your Program Create your user interface (GUI). Use different font styles but don’t overdo it, Use colors, and Use graphics (You can find all kinds of...
using the C programming language I need a program that includes comments/ screen shots that it...
using the C programming language I need a program that includes comments/ screen shots that it works/ and the code it self for a hang man game this game has to be to complie no errors please you can even keep it super basic if u want and no( studio.c) that never works THANK UUUUUU
This problem needs to be solved with source code. I need a C++ program that will...
This problem needs to be solved with source code. I need a C++ program that will help me solve this question. I need it in C++, please. Writing with comments so it maybe cleared. 1.2. We received the following ciphertext which was encoded with a shift cipher: xultpaajcxitltlxaarpjhtiwtgxktghidhipxciwtvgtpilpit ghlxiwiwtxgqadds. 1. Perform an attack against the cipher based on a letter frequency count: How many letters do you have to identify through a frequency count to recover the key? What is...
Need the correct line of code for c program to solve  this equation . i is a...
Need the correct line of code for c program to solve  this equation . i is a value that the program all ready calculates from user imput. t i = (x*1000)+(y*500)+(z*250
I have to complete all //to do comments for the following code: /** * A ShoppingBasket...
I have to complete all //to do comments for the following code: /** * A ShoppingBasket holds zero or more Products and can provide information * about the Products. One can add Products to a ShoppingBasket during its * lifetime, reset the ShoppingBasket, create a copy which contains Products of * at least a certain value, and make various queries to the ShoppingBasket. * (Thus, the number of Products that will be stored by a ShoppingBasket object * is not...
C++ program, include comments stating what each part of code does please. I want to be...
C++ program, include comments stating what each part of code does please. I want to be able to understand it so I'll be more knowledgeable in the future. The program is multiple files(fibonacci.h file, fibonacci.cpp file, main.cpp file and loops_simple_data_test.cpp). After the directions I also included any starter code or comments left by my professor within the files to aide us. Directions: In folder 04_loops_simple_data write prototype and definition for string value - return function get_fibonacci with an int parameter...
Please write a complete C coding program (NOT C++) that has the following: (including comments) -...
Please write a complete C coding program (NOT C++) that has the following: (including comments) - declares two local integers x and y - defines a global structure containing two pointers (xptr, yptr) and an integer (z) - declares a variable (mst) by the type of previous structure - requests the values of x and y from the user using only one scanf statement - sets the first pointer in the struct to point to x - sets the second...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT