CSE 247 Module 12: Diffie–Hellman
Cracking the Code
As usual, do a Team…Pull to get code updates.
Some of the code for this studio is in the studio12 package of
your studios source folder, and some is in the dh package
of your labs source folder. This is because some of the code
is shared with the lab you will do.
- Find and open the DemoCaesar class in the dh.demo package
of your labs source folder.
- Run it a few times to see how it produces rotated text, but only of
lower-case characters. All other characters, such as upper-case
characters and punctuation, are preserved.
- Take a look at the gen method of the Caesared class,
found in the dh.utils package. This kind of method is known
as a factory method because it generates an instance of its
class based on the supplied input values. If the input is a lower-case
character, the Caesared instance remembers that it is rotated,
but the rotation amount is not recorded.
- The unRotate(int) method should produce the same character
as originally supplied to gen, if the unrotation amount is the
- The DemoCaesar method knows the rotation amount so it can
use the unRotate method to decrypt the encrypted character.
Make sure you understand how Caesared works. Talk it over with
your studio partners.
Questions for you to answer, but no need to write them up:
The DemoCaesar class picks a random rotation value between 0
and 25, inclusively. What would happen if it chose a value outside that
range? For example, 26 or 27?
You can try this by assigning rot a fixed value such as 26 and
run the DemoCaesar class again.
What would happen if you supplied the value 247?
- OK the NSA is now relying upon you to crack the code.
- Find and open the BreakCaesar and TextBreakCaesar
classes in the studio12 package of your studios folder.
- Run TextBreakCaesar. It creates a string based on
the preamble of the US Constitution, but with the words
scrambled so you can't rely on their order. That string is then subjected to
a rotation of its letters.
Below is a sample of the output:
The top portion shows unrotated text (actually, text rotated with a rotation value
of 0). The original plain text is shown, followed by the rotated text (by 0)
and then the unrotated text (by 0). This zero-rotate test is always performed
when you run the JUnit test.
The next part of the output shows testing with random rotation values,
in this case 24. The original text is shown, followed by the rotated text.
Rotating forward by 24 is the same as going backward by 2, modulus 26. Thus
d is replaced by b and so on in the rotated text.
Note that punctuation and upper-case letters are left alone.
- Note also that the words are scrambled between each test, so you can't
rely on their order. No need to thank me, really.
- The unit test then asks BreakCaeasar for the rotation value,
but sadly this is currently returned as 0. Thus the unit test fails.
- Take a look at the modest and unassuming method getRotation().
Your studio group must brainstorm how to determine the rotation factor.
To help you in that process, the chars array contains the rotated
message with one character at each index of the array.
All of the brains of the analysis has to go into the getRotation()
method or a helper. Do not change any of the other methods.
Once you correctly return the rotation value from that method, the unit
test will pass, and you will be awarded the Caesar Star of Excelence (CSE).
If you have time, start to look over the lab for
Submitting your work (read carefully)
- If there is a file for you to complete in studiowriteups,
please respond to
the questions and supply any requested information.
- You must commit and push all of your work to your repository. It's best to do this
from the top-most level of your repository, which bears your name and student ID.
- Follow the instructions in the green box below to receive credit for your work.
Last modified 14:54:22 CDT 31 October 2016
When you done with this studio, you must be cleared by the TA to receive credit.
- Commit all your work to your repository
- Fill in the form below with the relevant information
- Have a TA check your work
- The TA should check your work and then fill in his or her name
- Click OK while the TA watches
- If you request propagation, it does not happen immediately,
but should be posted in the next day or so
This demo box is for studio 12