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: //...
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...
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...
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...
I need the code for a C++ program that creates an array of 5000 String objects...
I need the code for a C++ program that creates an array of 5000 String objects that will store each word from a text file. The program will read in each word from a file, and store the first 5000 words in the array. The text file should be read in from the command line.
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...
I need assistance translating a custom C++ program to MIPS. My C++ code is the following:...
I need assistance translating a custom C++ program to MIPS. My C++ code is the following: I have made numerous attempts on my own to no avail, any assistance is appreciated. Also, template code for this solution is provided below: #include int moveRobots(int *, int *, int, int ); int getNew(int, int); int main() { int x[4], y[4], i, j, myX = 25, myY = 25, move, status = 1; // initialize positions of four robots x[0] = 0; y[0]...
Source code with comments explaining your code in C# Program 2: Buh-RING IT! For this assignment,...
Source code with comments explaining your code in C# Program 2: Buh-RING IT! For this assignment, you’re going to simulate a text-based Role-Playing Game (RPG). Design (pseudocode) and implement (source) for a program that reads in 1) the hero’s Hit Points (HP – or health), 2) the maximum damage the hero does per attack, 3) the monster’s HP and 4) the maximum monster’s damage per attack. When the player attacks, it will pick a random number between 0 and the...
Also please add comments on the code and complete in C and also please use your...
Also please add comments on the code and complete in C and also please use your last name as key. The primary objective of this project is to increase your understanding of the fundamental implementation of Vigenere Cipher based program to encrypt any given message based on the Vignere algorithm. Your last name must be used as the cipher key. You also have to skip the space between the words, while replicating the key to cover the entire message. Test...
this is a python code that i need to covert to C++ code...is this possible? if...
this is a python code that i need to covert to C++ code...is this possible? if so, can you please convert this pythin code to C++? def main(): endProgram = 'no' print while endProgram == 'no': print # declare variables notGreenCost = [0] * 12 goneGreenCost = [0] * 12 savings = [0] * 12 months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'] getNotGreen(notGreenCost, months) getGoneGreen(goneGreenCost, months) energySaved(notGreenCost, goneGreenCost, savings) displayInfo(notGreenCost, goneGreenCost, savings, months)...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT