a) Create a new Jupyter Notebook and start your program by asking the user for a text to encode and the shift value. Then begin the structure of your program by entering in this loop (we'll build on it more in a bit): encoded Text = *** for letter in text: encoded Text = encoded Text + letter What does this loop do? Make sure you understand what the code does before moving on!

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter5: Repetition Statements
Section5.6: Nested Loops
Problem 2E
icon
Related questions
Question

Q1: Secret Messages 

Implement a Caesar cipher to encrypt messages. 

a) Create a new Jupyter Notebook and start your program by asking the user for
a text to encode and the shift value. Then begin the structure of your program
by entering in this loop (we'll build on it more in a bit):
encoded Text = ""
for letter in text:
encoded Text = encoded Text + letter
What does this loop do? Make sure you understand what the code does before
moving on!
b) Now modify the program above to replace all the alphabetic characters with
'x'. For example:
Enter text to encrypt: Mayday! Mayday!
Enter shift value: 4
The encoded phrase is: Xxxxxx! Xxxxxx!
c) Now modify your code, we are going to apply the cipher only to the alphabetic
characters and we will ignore the others. So, your program needs to produce
the encoded string using the cipher algorithm with the shift value entered by
the user. Let's see how one might do a cyclic shift. Let's say we have the
sequence:
012345
If we use a shift value of 4 and just shift all the numbers, the result will be:
456789
Page 3 of 5
We want the values of the numbers to remain between 0 and 5. To do this we
will use the modulus operator. The expression x%y will return a number in the
range 0 to y-1 inclusive, e.g. 4%6 = 4, 6 % 6 = 0, 7% 6 =1. Thus, the result of the
operation will be:
450123
Hint: Note that the ASCII value of 'A' is 65 and 'a' is 97, not 0. So, you will have
to think how to use the modulus operator to achieve the desired result. Apply
the cipher separately to the upper- and lower-case letters.
Here is what you program should output:
Enter your text to Encrypt: Mayday! Mayday!
Enter your encryption key number (1-26): 4
The encrypted message is: Qechec! Qechec!
d) Finally, modify your program to decrypt the ciphertext back to the plaintext.
(Decryption is the opposite of encryption).
Transcribed Image Text:a) Create a new Jupyter Notebook and start your program by asking the user for a text to encode and the shift value. Then begin the structure of your program by entering in this loop (we'll build on it more in a bit): encoded Text = "" for letter in text: encoded Text = encoded Text + letter What does this loop do? Make sure you understand what the code does before moving on! b) Now modify the program above to replace all the alphabetic characters with 'x'. For example: Enter text to encrypt: Mayday! Mayday! Enter shift value: 4 The encoded phrase is: Xxxxxx! Xxxxxx! c) Now modify your code, we are going to apply the cipher only to the alphabetic characters and we will ignore the others. So, your program needs to produce the encoded string using the cipher algorithm with the shift value entered by the user. Let's see how one might do a cyclic shift. Let's say we have the sequence: 012345 If we use a shift value of 4 and just shift all the numbers, the result will be: 456789 Page 3 of 5 We want the values of the numbers to remain between 0 and 5. To do this we will use the modulus operator. The expression x%y will return a number in the range 0 to y-1 inclusive, e.g. 4%6 = 4, 6 % 6 = 0, 7% 6 =1. Thus, the result of the operation will be: 450123 Hint: Note that the ASCII value of 'A' is 65 and 'a' is 97, not 0. So, you will have to think how to use the modulus operator to achieve the desired result. Apply the cipher separately to the upper- and lower-case letters. Here is what you program should output: Enter your text to Encrypt: Mayday! Mayday! Enter your encryption key number (1-26): 4 The encrypted message is: Qechec! Qechec! d) Finally, modify your program to decrypt the ciphertext back to the plaintext. (Decryption is the opposite of encryption).
Expert Solution
steps

Step by step

Solved in 4 steps with 9 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
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr