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

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...
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)...
/* Assignment : Complete this javascript file according to the individual instructions given in the comments....
/* Assignment : Complete this javascript file according to the individual instructions given in the comments. */ // 1) Utilize comments to prevent the following line from executing alert('Danger!'); // 2) Assign a value of 5 to a variable named x // and print the value of x to the console // 3) Assign a value of 10 to a variable named myNum // and print the value of myNum to the console // 4) Assign the product of x...
/* Assignment: Complete this javascript file according to instructions given in the comments. */ // 1)...
/* Assignment: Complete this javascript file according to instructions given in the comments. */ // 1) Declare a variable named myName equal to your first name //Firstname is Susan // Construct a basic IF statement that prints the variable to the // console IF the length of myName is greater than 1 // 2) Copy your IF statement from above and paste it below // Change the IF statement to check if the length of myName // is greater than...
I need code written in java for one of my projects the instructions are Write a...
I need code written in java for one of my projects the instructions are Write a program that interacts with the user via the console and lets them choose options from a food menu by using the associated item number. It is expected that your program builds an <orderString> representing the food order to be displayed at the end. (See Sample Run Below). Please note: Each student is required to develop their own custom menus, with unique food categories, items...
C Code! I need all of the \*TODO*\ sections of this code completed. For this dictionary.c...
C Code! I need all of the \*TODO*\ sections of this code completed. For this dictionary.c program, you should end up with a simple English-French and French-English dictionary with a couple of about 350 words(I've provided 5 of each don't worry about this part). I just need a way to look up a word in a sorted array. You simply need to find a way to identify at which index i a certain word appears in an array of words...
Write a complete Java program, including comments in each method and in the main program, to...
Write a complete Java program, including comments in each method and in the main program, to do the following: Outline: The main program will read in a group of three integer values which represent a student's SAT scores. The main program will call a method to determine if these three scores are all valid--valid means in the range from 200 to 800, including both end points, and is a multiple of 10 (ends in a 0). If the scores are...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT