Homework 4

advertisement
CSc 250 - Assignment# 4, Prof Mitchell, Feb 17, 05
Implementing Playfair’s Cipher and some Cryptanalysis of Playfair
Due date: Class time, March 3 --Separator character specification added 2/27
#1. Introduction
You must develop a program (in any language) that implements the Playfair
substitution cipher. The program must be able to read any text file “fi” containing
ordinary English prose and punctuation (that is, the file contains no digits or special
characters). After re-representing fi, call it fiUC (as detailed in the next section), your
program encrypts fiUC using the Playfair algorithm and key k as discussed in class and
Web slides. The encryption result fik = Ek(fiUC) is a sequence of upper-cases
characters. As described later, you must build frequency plots of ciphertext pairs. This
does some of the analysis of Playfair’s effectiveness against anagramming attacks.
#2. Encryption specifications
Each application of your cipher must do the following steps:
1. Read and covert fi into a continuous string of characters in another file, here
called fiUC by:
1. Replacing each lowercase character with its uppercase equivalent
2. Replace each occurrence of J with I
3. Removing all punctuation and space characters that separate words
4. Whenever an odd-and-even character are the same, use ‘X’ as the character
to separate those repeated characters in fi; doing this allows use of the 3case encipherment of odd-and-even character pairs as defined in the class
slides. Note that as X separator characters are added, the remaining
plaintext character odd vs. even positions changes. Examples of X as
plaintext pair separator: 1) ALASKA…  ALASKA…; 2) OOPS… 
OXOPS…; 3) ALLWET…  ALLWET… The repeated Ls are not in an odd-even
pair; 4) OOOPERATOR…  OXOXOPERATOR… In this last example, the first
OO pair needed X separator, but then the original second and 3rd O become the new 3rd
and 4th plain characters, and thus they also need an X separator.
5. Use one ‘Z’ as the fill character when fiUC is an odd number of characters
1
2.
Choose key two distinct ki (see next paragraph) for encryptions of fiUC.
Limit ki length to between 8 and 12 characters inclusive. Consider J to be
occurrences of I in ki. Repeated characters are not allowed in ki (even after J is
replaced by I). For the two encryptions of fiUC required in this assignment, use
each ki value (this will show sensitivity of frequencies to ki)
Choosing the two ki will involve a “key registration” process, done as follows.
After you select your two keys, email to instructor these 3 values:
YourLastName+FirstInitial, k1, k2
You will be given email confirmation that your keys are OK. Key choice is
FirstComeFirstServed, so your ki must be different from all ki already registered.
You will be able to view the already-chosen keys by running Oracle DB query:
select pkey
from mitchell.playfair_key
order by pkey;
3. Encipher fiUC with key ki to E(fiUCki) = fki
4. For each fki , build (using Excel or equivalent, no hand-drawn plots accepted, see
plot example below) a frequency plot consisting of:
(number of times this pair occurs in cki), plotted vertically vs. the 252 pairs
(AA, AB, … , AZ, BA, … , BZ, … , ZA, … , ZZ) as shown. However, on
the horizontal axis, draw attention and highlight in some visual way, the ki
value used and the three highest frequency pairs (for example: PD, EB,
WH). On each plot, show the ki at top. If more than one pair has highest
frequency, you must label all 3.
Note: Landscape format might be the best layout, given the large number
of x-axis values plotted.
2
Frequency of ciphertext pairs - KEY: MONARCHY
18
16
Frequency of this pair
14
12
10
8
6
4
2
0
AA
EB
PD
WH
ZZ
Note: You can save a lot of tedious work by having your encryption program also
generate the plot pairs for Excel input.
#3. Input file “fi” and Hand INs
A FIRST, FOR YOUR TESTING PURPOSES, physical file corresponding to fi is
posted on the Web site:
.../homework/ALL’S_WELL_THAT_ENDS_WELL.txt
and is the full plaintext of one of Shakespeare’s comedies
TURN IN: 2 Excel plots as described/displayed above, one for each ki. Ideally, the
ciphertext pairs should occur with equal frequency. Equal frequencies will, of course,
not happen in practice, but it will be interesting to see 1) how close to equal frequencies
your results are, and 2) how much variation occurs in the frequencies between the 2
encipherments.
TURN IN: A copy of your source program
[ Be prepared to answer questions about your source program and its internals ]
3
Download