CS8, 09M, UCSB
H08: (Based on Miller/Ranum, Chapter 3 (pp. 94-99) Total points: ? (printable PDF)
Accepted: on paper, in lecture (11am in HFH1132) on Wednesday, August 26th
No email submission allowed.
Name: (2 pts)______________________________ UCSBNetID (2 pts) _____________________
Lab Section (1 pts) Circle one: Thu 11am Thu 12:30pm Unknown
Circle the one you plan to attend, which may or may not be the one you are registered for.
Read pages 94-98 in Chapter 3. Then answer these questions. You may want to have the code from these pages available—you can find it at the links below.
- You may have noticed that parents of small children sometimes spell out words as a means of trying to keep their children from knowing what they are talking about. For example, they might say:
Remember to pick up some i-c-e c-r-e-a-m for the p-a-r-t-y.
Or, if you have a dog, you might say: I need to give the d-o-g his weekly b-a-t-h.
You spell out the words so that the small children or pets don't hear certain words that will cause them behave in ways that may be annoying to the adults around them.
Page 93 describes the terms plaintext, ciphertext, encryption and decryption.
Describe how each of these four words applies to the situation described—that is, in this situation:
- ( 3 pts) What is the plaintext?
- ( 3 pts) What is the ciphertext?
- (3 pts) What is the encryption?
- (3 pts) What is the decryption?
- (5 pts) Page 95 describes a process for encrypting "It was a dark and stormy night" using the "rail fence cipher", with the result being "twsadr_n_tryngtI_a__akadsom_ih"
What is the encryption of the phrase "Go Gauchos" in this same cipher?
- (5 pts) Here is a secret message encoded with the rail fence Cipher. What is the secret message?
'S_sfnC8i_u'
Please turn over for more problems
Continued from other side
- Look at program listing 3.2 on p. 95. In plain english:
- (5 pts) What does this function "consume", i.e. take as an argument to a function call?
- (5 pts) What does this function "produce", i.e. return as the result of a function call?
- (2 pts) In your book, the lines of this listing are numbered. On line 7, does the + sign mean addition or concatenation?
- (2 pts) Same question, line 9?
- (2 pts) Same question, line 10?
- (2 pts) Same question, line 11?
- (5 pts) On p. 98, in listing 3.3, we see this line at line 2
halfLength = len(cipherText) // 2
We see that the value of halfLength is then used on lines 3 and 4, in a "slice" operation. (Slice operations are described earlier in Chapter 3, and in the text on pages 94-98).
My question to you: in plain english, what is the reason for using the // operator here?
Hints: It will definitely help you to read through the text on pages 94-98 that describes the encryption/decryption algorithm. However the answer to the question is not just "waiting for you in the text"—you'll have to do something additional thinking.
Here are some clues to guide you:
- Think about what happens when we encrypt a message with four characters—that is, first go back to listing 3.2, and run it on, for example, "pear".
- Think about what happens when we encrypt a message with three characters, e.g. "dog"
- Then think about what will happen when want to decrypt either of those messages—particularly what happens on line 2, and then lines 3 and 4 of listing 3.3
End of H08