Question: 11.3 LAB: Convert String to Cyphertext cstring Implement the following (Called a Ceasar Cypher, since it was used in Ceasar's time) using this function prototype
11.3 LAB: Convert String to Cyphertext cstring
Implement the following (Called a Ceasar Cypher, since it was used in Ceasar's time) using this function prototype in the same file
char* cypher(string str, int rotate);
The idea is that you will declare a variable of type string and give it a value in main. Then pass it into the cypher function.
Cypher will create a cstring by copying the str to a new char* of size str.size(). Remember that you can covert with str.c_str( ).
Then you will rotate ever letter by an amount passed into the function. If you look at the ascii table You will see that A is 65 and z is 122. We want to keep every character between these ascii codes. So, you will probably need an if statement noting: If after adding the rotate value and taking the modulus of one after z (123), the value is between 65 and 123, then set the character to that value. Otherwise, because you did a mod of 123, you know the number is no larger than 122 (then goes back to zero).so in that case you would want to add 65 to take it to A.
Don't forget to return the char*. Then print out the cstring with puts. e.g.
char* cstr = new char[size]; puts(cstr);
For output, set the string to "ABC" and call cypher("ABC", 0);
main.cpp
#include
#include
using namespace std;
char* cypher(string str, int rotate);
int main() {
/* Type your code here. */
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
