CS202 Assignment 3-- Caesar’s Challenge (group assignment)
Due: 11:59pm 06/26/2023(Monday)
Introduction
As a renowned detective, Sherlock Holmes receives a lot of mail. Some of his mail included
puzzles from his rivals, attempting to be the first to confuse Sherlock. Unfortunately, many of
these correspondents are not very creative. In particular, he frequently gets “secret” messages
encoded with Caesar ciphers. Although these ciphers are trivial for Sherlock to crack, he has
much better things to do, and has therefore passed this task on to Dr. Watson. Help relieve Dr.
Watson of this boring job by writing a program to automatically decipher these messages.
Caesar cipher
A Caesar cipher takes as input a message string and a shift value n, and shifts each letter in the
message forward through the alphabet by n letters. For example, let's say n = 1. Then, shifting
the letter ‘A’ forward by 1 would return ‘B’, and shifting ‘B’ forward by 2 would return ‘D’.
The alphabet should wrap around - shifting ‘Z’ forward by 1 would return ‘A.’ For example,
shifting the word “HAL” forward by 1 would return “IBM”, and shifting “Abcdefghijklm,
nopqrstuvwxyz!” forward by 5 will return “Fghijklmnopqr, stuvwxyzabcde!”. (Notice that the
case of the letters is preserved, and non-letter symbols are unchanged.)
It might be easier to understand what "shifting forward" means if you look
at https://computerscienced.co.uk/site/caesar-cipher-wheel/caesar-cipher/
Decoding a message encoded with a shift of n is equivalent to encoding a message with a shift
of 26 − n. Of course, these rivals haven’t given Sherlock the shift value - your program has to
figure it out itself. One way to do this is by shifting the message by all 26 possible shifts, and
returning the one that seems most like English. To do this, you might find helpful this 26-
element array, holding the frequencies of each letter in English:
double[] englishFrequencies = {0.08167, 0.01492, 0.02782,
0.04253, 0.12702, 0.02228, 0.02015, 0.06094, 0.06966,
0.00153, 0.00772, 0.04025, 0.02406, 0.06749, 0.07507,
0.01929, 0.00095, 0.05987, 0.06327, 0.09056, 0.02758,
0.00978, 0.02360, 0.00150, 0.01974, 0.00074};
That is, 8.167% of all letters in English text are A, 1.492% are B, ... and 0.074% are Z.
Specification
Implement the class CaesarDecipher, which consists of the method
public static String decipher(String ciphertext);
Example
Input
decipher("Me m dqzaizqp pqfqofuhq, Etqdxaow Taxyqe dqoquhqe m bxqftadm ar rmz
ymux.");
Output
As a renowned detective, Sherlock Holmes receives a plethora of fan mail.
Hints:
Use a brute-force strategy to try every possible key value (1 ~ 25) and calculate the
frequency error that it generates, 代写CS202程序for example, the frequency error can be the summation of the
absolute frequency difference between the actual frequency of a letter in the deciphered text and
the given frequency of that letter in English text. For example, for a key candidate of 6, letter ‘W’
would be deciphered to letter ‘C’, and the absolute frequency difference would be:
| occurrence of letter ‘C’ in the deciphered text – 0.02782 |
After calculating the frequency errors for all candidate key values, choose the one with the smallest
frequency error, and use that key to decipher the ciphertext.
Submission requirements:
1. Submit your .java file to canvas. Use extra methods when necessary. Do not put everything
in the decipher().
2. A screenshot of your running result. (png, jpg, pdf, or docx)
3. Each group can have at most two students. If you work with another student in a group,
submit a README.docx or README.txt containing both students’ names and a
description of each student’s work in this assignment. Both students need to submit his/her
assignment to canvas. I might randomly pick students to ask you give me a demo and
explain how your code works.
4. Make sure your code is free of compile errors. A project with compile errors in it will earn
you a very low grade.
5. Follow the Java style guide (Files/ASSIGNMENTS/JavaStyleGuide.pdf) and comment
your code whenever necessary.
6. Refer to (Files/AQuickGuide2Eclipse.pdf) for how to import an existing project into
Eclipse, how to open a workspace, etc.
Academic Honesty:
Your code must be your own. Any format of sharing code is not allowed and is considered
plagiarism.
CS202 Final Project—Spelling Bee (group assignment)
Due: 11:59pm 06/30/2023(Friday)
No late submission is accepted.
Assignment
Follow the instructions in the assignment PDF file at the following link:
http://nifty.stanford.edu/2022/eroberts-spelling-bee-wordle/SpellingBee/java/SpellingBeeAssignment.pdf
Please read the PDF file carefully and let me know if you have any questions.
The assignment starter Java file is: Final_SpellingBee.zip. (This is a zipped Eclipse project folder
containing the starter code. You can import it to an Eclipse workspace and add code to it.)
Grading
To receive 100 on this assignment, you need to complete the first 3 milestones from the
assignment that you can find on pages 5 and 6 in the above-mentioned
SpellingBeeAssignment.pdf file.
Milestone 1 is worth 40 points, Milestone 2 is worth 30 points, and Milestone 3 is also worth 30
points.
Milestone 1 points:
• The letters appear on the screen when the user presses ENTER (10 points).
• The condition of "The puzzle must contain exactly seven characters" is met (10 points).
• The condition of "Every character must be one of the 26 letters" is met (10 points).
• The condition of "No letter may appear more than once in the puzzle" is met (10 points).
Milestone 2 points:
• The condition of "The word is at least four letters long" is met (10 points).
• The condition of "The word does not contain any letters other than the seven letters in the
puzzle" is met (10 points).
• The condition of "The word contains the center letter, which appears at the start of the
puzzle string" is met (10 points).
Milestone 3 points:
• Scoring is implemented (10 points).
• Pangram is implemented. Make sure that you use Color.BLUE to make the pangram
word stand out in blue color (10 points).
• Both "the number of words found" and "the total score" are shown on the screen (10
points).
Bonus
If you complete the 4th milestone (see page 6 of the SpellingBeeAssignment.pdf file), you will
receive 30 bonus points in addition to your 100 points for this assignment.
Submission
1. Please upload your zipped Eclipse project folder that you completed, based on the
provided starter code.
2. A pdf or docx file containing screenshots of your running results. Specifically, show a few
test cases for all the milestones that you completed. In your screenshots, create your own
spelling bee problems, instead of using the example ones in the PDF file.
3. Each group can have at most two students. If you work with another student in a
group, submit a README.docx or README.txt containing both students’ names
and a description of each student’s work in this assignment. Both students need to
submit his/her assignment to canvas. I might randomly pick students to ask you give me
a demo and explain how your code works.
4. Make sure your code is free of compile errors. A project with compile errors in it will earn
you a very low grade.
5. Follow the Java style guide (Files/ASSIGNMENTS/JavaStyleGuide.pdf) and comment
your code whenever necessary.
6. Refer to (Files/AQuickGuide2Eclipse.pdf) for how to import an existing project into
Eclipse, how to open a workspace, etc.
Academic Honesty:
Your code must be your own. Any format of sharing code is not allowed and is considered
plagiarism.
WX:codehelp
标签:10,code,assignment,Challenge,Caesar,letter,CS202,your,points From: https://www.cnblogs.com/javanew/p/17520823.html