As usual, create two directories for today's class. Create a
directory called lecture26
under activities, and
a directory called lab26
under labs.
Time to see what fate has in store for your quiz submission! Including activities from Lectures 23, 24, and 25.
Answer the questions on the handout provided. Once you have completed the on paper portion of the review, continue on to answering the following programming questions.
strange_condition
that evaluates
to True if and only if parameters
x
and y
are greater than 37 but not equal
to each other.
count_chars
that takes as a
parameter a string s
and a character
c
(String of length 1), and returns the number of times
c appears in s. Do not use any built in
string methods for this question!
get_maximum_value(s1, s2, s3)
,
which takes as parameters 3 integer values, and returns the integer
with the highest value.
On Wednesday, we saw how easy it was to break the Caesar cipher. While the substitution cipher is much more complex to break than Caesar, it still isn't unbreakable. As a matter of fact, We were able to to it pretty easily the first day of class. Today, I'll describe a formal way to go about breaking the substitution cipher.
In order to break the Substitution Cipher you wrote on Wednesday, we
need to be able to figure out which character is the most frequently
occuring in the ciphertext. You can easily get a count of how often a
specific character occurs using the count
method that the String class provides.
Consider the following ciphertext:
uikjloweiriouhgoisndfglkxcjnbpoiuhqouyhdalkfkdjhnfakehwoaliundf
What is the most common character in this seemingly random sequence of characters? Your process is likely: Count all the a's, count all the b's, count all the c's, ... then, figure out which one was the highest. However, you can't store some arbitrary number of counts. So, you should keep track of the letter with the highest count, and update that letter when you find one of a higher count.
In a file called frequency_analysis.py
, write a
function called get_maximum_character
. This function
should take a single parameter: a string of lowercase, alphabetic
characters. It should return the lowercase, alphabetic character
that occured most often in the input string.
Don't forget to test your function! Make sure that you sanely handle the case where multiple letters have the same counts.
When you have finished, create a tar file of your lab26
directory. To create a tar file, execute the following commands:
cd ~/cs120/labs tar czvf lab26.tgz lab26/
To submit your activity, go to cseval.roanoke.edu. You should
see an available assignment called Lab Assignment 26
. Only
one of your pair should submit your activity. Make sure both partners
are listed in the header of your files.
Do not forget to email your partner today's files!