NOTE: The S’more is entirely optional and will not be part of your grade in EECS 183. It is for extra practice and fun after completing the regular project.
WARNING: The S’more is not part of your grade. You MUST complete and submit the regular project
Have time for a quick challenge? As we hinted earlier, breaking the Caesar cipher is fairly easy, so long as you can recognize correct English words, since there are only 25 keys you’d have to check. And although computers are very good at quickly encoding characters and going through different keys, they unfortunately understand only 0s and 1s and not ABCs. So in order to tell the computer which words exist and which don’t, we’ll have to provide it a file with all (or close to all) words in the English language.
First, read up on how to read from a file. You may do so in zyBooks or in other resources, such as cplusplus.com.
In the S’more distribution code
(smore3.zip) you’ll
find two files: dictionary.txt
and frequent.txt
. The former
contains 235,886 English words that one of our staff found on his
Mac laptop in /usr/share/dict/words
. The latter is a shorter list
of some of the more frequent words.[1] Depending on your
implementation, your program can take a long time to run, so it
might be faster to test with a smaller dictionary.
Implement, in a file called decrypt.cpp
, a program that reads a
message (a line) encrypted using Caesar cipher, then breaks the
cipher and prints a key followed by a decrypted message, each on a
new line, nothing else. The message is read from the console without
a prompt to the user. Your program should behave as illustrated by
the sample output below, wherein red underlined text represents some
user’s input.
Ze. naq Zef. Qhefyrl bs ahzore sbhe, Cevirg Qevir, jrer cebhq gb fnl gung gurl jrer cresrpgyl abezny, gunax lbh irel zhpu.
13
Mr. and Mrs. Dursley of number four, Privet Drive, were proud to say that they were perfectly normal, thank you very much.
Be sure to #include "utility.h"
and use functions you implemented
in utility.cpp
. You program must read a list of words from a file
called dictionary.txt
(not frequent.txt
). The rest of the design
is up to you!
What key is the top of this project’s specification encrypted with?
In order to read from a file such as dictionary.txt
, you must place it
in the correct location.
There are a few things that must be done for Xcode. First, ensure that Derived Data is stored relative to your project folder. Select Xcode > Preferences in the menu bar, click on Locations icon at the top on the window and choose Relative next to Derived Data. This will ensure that executables are saved in your Project folder.
Then, tell Xcode to look for files in the folder where all other project files are stored. From the menu bar, choose Product > Scheme > Edit Scheme.
Select Run on the left, Options on top and then select the checkbox Use custom working directory and navigate to your Project folder where you will store input files.
Now you can place input txt
files right with your .h
and
.cpp
files.
NOTE: If you move your project folder, you’ll have to reset the project’s working directory.
Fortuately, Visual Studio’s working directory is the project folder itselt. So head to the project folder that is named the same as the project. There should be another folder with that same name. Place the input files in that second folder.
Make sure that you’ve submitted the main part of the project.
Submit your implementation of S’more to the Autograder here:
https://autograder.io/web/project/2683. Upload decrypt.cpp
and
click Submit. We will do a very simple (non-exhaustive) check of
your program, so it is your responsibility to ensure that it’s
correct.
[1] https://launchpad.net/ubuntu/bionic/amd64/wamerican-small/2017.08.24-1