C++ starter code  /* Cipher Lab using C strings */

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

C++ starter code 

/* Cipher Lab using C strings */

/* Running the program looks like:
Enter some lower-case text: hello
Shifting 0 gives: hello
Shifting 1 gives: ifmmp
Shifting 2 gives: jgnnq
Shifting 3 gives: khoor
Shifting 4 gives: lipps
Shifting 5 gives: mjqqt
Shifting 6 gives: nkrru
Shifting 7 gives: olssv
Shifting 8 gives: pmttw
Shifting 9 gives: qnuux
Shifting 10 gives: rovvy
Shifting 11 gives: spwwz
Shifting 12 gives: tqxxa
Shifting 13 gives: uryyb
Shifting 14 gives: vszzc
Shifting 15 gives: wtaad
Shifting 16 gives: xubbe
Shifting 17 gives: yvccf
Shifting 18 gives: zwddg
Shifting 19 gives: axeeh
Shifting 20 gives: byffi
Shifting 21 gives: czggj
Shifting 22 gives: dahhk
Shifting 23 gives: ebiil
Shifting 24 gives: fcjjm
Shifting 25 gives: gdkkn
*/

#include <iostream>
#include <iomanip>
#include <cctype>

using namespace std;

// Global constants
const int MaxWordSize = 81; // 80 characters + 1 for NULL


// Given an array of characters and a shift value:
// shift each character in the original text by some amount,
// storing the result into the shiftedText array.
// Remember: Wrap around at the end of the alphabet.
// *** In the line below you must supply the function
// return type and the parameter(s) ***
? shiftTheText( ? )
{
// Loop through each character in the C string, startingText
// When the character is an alphabetic character,
// shift it by adding the shift value.
// Then store the resulting character in its proper spot
// in the shiftedText C string.


}


int main()
{
// Initialize the variables
char startingText[ MaxWordSize];
char shiftedText[ MaxWordSize];

cout << "Enter some lower-case text: ";
cin >> startingText;

for( int shiftValue = 0; shiftValue < 26; shiftValue++) {
// In the function call below you need to pass the starting text array, the shift value, and the shifted text array.
shiftTheText( );
cout << "Shifting " << setw( 2) << shiftValue << " gives: " << shiftedText << endl;
}

return 0; // Keep C++ happy

}// end main()

 

7.7 Caesar Cipher
Today you will be decoding secret messages.
We will be using Caesar Cipher, that was used by Caesar (the roman politician and military general) to pass messages to his army.
It is a shift cipher which works by shifting the positions of the text.
For example if you had to encrypt the word ocean by shifting the alphabets by 5: we would shift 'o' by 5 to get 't, 'c' by 5 to get 'h' and so on.
So the word,
PlainText: **ocean**
Shifted Text: **thjfs**,
Cipher : 3hift by 5.
Where we can assume if plaintext to cipher map as below for shift by 5:
Plain:
ABCDEFGHIJKLMNOPQRSTUVWXYZ
Cipher: FGHIJKLMNOPQRSTUVWXYZABCDE
Shifting by 5 means alphabet A becomes alphabet F i.e. A the first alphabet becomes the (1+5=6) alphabet F, and so on. HINT: The
alphabets wrap so that A comes after Z.
Shifting thjfs by 21 gives you ShiftedText: ocean
Running the program looks like:
Enter some lower-case text: hello
Shifting 0 gives: hello
1 gives: ifmmp
Shifting 2 gives: jgnng
Shifting
Shifting 3 gives: khoor
Shifting
4 gives: lipps
5 gives: mjqqt
6 gives: nkrru
7 gives: olssv
8 gives: pmttw
9 gives: qnuux
Shifting
Shifting
Shifting
Shifting
Shifting
Shifting 10 gives: rovvy
Shifting 11 gives: spwwz
Shifting 12 gives: tqxxa
Shifting 13 gives: uryyb
Shifting 14 gives: vszzc
Shifting 15 gives: wtaad
Shifting 16 gives: xubbe
Shifting 17 gives: yvccf
Shifting 18 gives: zwddg
Shifting 19 gives: axeeh
Shifting 20 gives: byffi
Shifting 21 gives: czggj
Shifting 22 gives: dahhk
Shifting 23 gives: ebiil
Shifting 24 gives: fcjjm
Shifting 25 gives: gdkkn
But, we have given you text that is shifted like thjfs from the above example. You have to shift the letters to read what it says.
We have given you the main. You will write your code in the functions.
Step 1: Write the function ?? shiftThetext(???), supply the parameters and the return type.
Step 2:)
• The function shiftThe Text() will shift each alphabet given by the shift integer.
• Given an array of characters and a shift value, shift each character in the original text by some amount, storing the result into the
shiftedText array.
• Wrap around at the end of the alphabet (like in the plaintext to cipher mapping A appears after Z).
• Running the test for Stage 2:
o only one of the output will make sense. (See example below: Shifting 17 gives: hello)
Enter some lower-case text: qnuux
Shifting o gives: gnuux
Shifting
1 gives: rovvy
2 gives: spwwz
3 gives: tgxxa
Shifting
Shifting
Shift ing
4 giveg. 1urvuo
Transcribed Image Text:7.7 Caesar Cipher Today you will be decoding secret messages. We will be using Caesar Cipher, that was used by Caesar (the roman politician and military general) to pass messages to his army. It is a shift cipher which works by shifting the positions of the text. For example if you had to encrypt the word ocean by shifting the alphabets by 5: we would shift 'o' by 5 to get 't, 'c' by 5 to get 'h' and so on. So the word, PlainText: **ocean** Shifted Text: **thjfs**, Cipher : 3hift by 5. Where we can assume if plaintext to cipher map as below for shift by 5: Plain: ABCDEFGHIJKLMNOPQRSTUVWXYZ Cipher: FGHIJKLMNOPQRSTUVWXYZABCDE Shifting by 5 means alphabet A becomes alphabet F i.e. A the first alphabet becomes the (1+5=6) alphabet F, and so on. HINT: The alphabets wrap so that A comes after Z. Shifting thjfs by 21 gives you ShiftedText: ocean Running the program looks like: Enter some lower-case text: hello Shifting 0 gives: hello 1 gives: ifmmp Shifting 2 gives: jgnng Shifting Shifting 3 gives: khoor Shifting 4 gives: lipps 5 gives: mjqqt 6 gives: nkrru 7 gives: olssv 8 gives: pmttw 9 gives: qnuux Shifting Shifting Shifting Shifting Shifting Shifting 10 gives: rovvy Shifting 11 gives: spwwz Shifting 12 gives: tqxxa Shifting 13 gives: uryyb Shifting 14 gives: vszzc Shifting 15 gives: wtaad Shifting 16 gives: xubbe Shifting 17 gives: yvccf Shifting 18 gives: zwddg Shifting 19 gives: axeeh Shifting 20 gives: byffi Shifting 21 gives: czggj Shifting 22 gives: dahhk Shifting 23 gives: ebiil Shifting 24 gives: fcjjm Shifting 25 gives: gdkkn But, we have given you text that is shifted like thjfs from the above example. You have to shift the letters to read what it says. We have given you the main. You will write your code in the functions. Step 1: Write the function ?? shiftThetext(???), supply the parameters and the return type. Step 2:) • The function shiftThe Text() will shift each alphabet given by the shift integer. • Given an array of characters and a shift value, shift each character in the original text by some amount, storing the result into the shiftedText array. • Wrap around at the end of the alphabet (like in the plaintext to cipher mapping A appears after Z). • Running the test for Stage 2: o only one of the output will make sense. (See example below: Shifting 17 gives: hello) Enter some lower-case text: qnuux Shifting o gives: gnuux Shifting 1 gives: rovvy 2 gives: spwwz 3 gives: tgxxa Shifting Shifting Shift ing 4 giveg. 1urvuo
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Types of Loop
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education