p3-ciphers

EECS 183 Project 3: Ciphers

Due Friday, 26 March 2021 at 8:00 p.m. (accepted until 11:59 p.m.)

Overview

In this project, you will move on to cryptography and you’ll be asked to encrypt and decrypt messages using three different encryption algorithms. The S’more part of this project will challenge you to “crack” others’ secret messages in ciphertext and convert them back to plaintext.

disk

Objectives

WARNING: Beware the autograder’s ability to detect cheating, see Honor Code for further information.

Honor Code

Collaboration Policy and the Honor Code

All students in the class are presumed to be decent and honorable, and all students in the class are bound by the College of Engineering Honor Code.

We want students to learn from and with each other, and we encourage you to collaborate. We also want to encourage you to reach out and get help when you need it.

You are encouraged to:

To clarify the last item, you are permitted to look at another student’s code to help them understand what is going on with their code. You are not allowed to tell them what to write for their code, and you are not allowed to copy their work to use in your own solution. If you are at all unsure whether your collaboration is allowed, please contact the course staff via the admin form before you do anything. We will help you determine if what you’re thinking of doing is in the spirit of collaboration for EECS 183.

The following are considered Honor Code violations:

The full collaboration policy can be found in the syllabus.

We run every submission against every other submission and determine similarities. All projects that are “too similar” are forwarded to the Engineering Honor Council. This happened to numerous students last semester. Also know that it takes months to get a resolution from the Honor Council. Discussing the project with other students will NOT be an issue. Sharing code between students, even if it’s just one function, will likely cause the cheating detector to identify both programs as “too similar”. We also search the web for solutions that may be posted online and add these into the mix of those checked for similarities. Searching the web, by the way, is something that we are very good at.

Any violation of the honor policies appropriate to each piece of course work will be reported to the Honor Council, and if guilt is established, penalties may be imposed by the Honor Council and Faculty Committee on Discipline. Such penalties can include, but are not limited to, letter grade deductions or expulsion from the University.

Also note that on all cases forwarded to the Engineering Honor Council the LSA Dean of Academic Affairs is also notified. Furthermore, the LSA rule is students involved in honor violations cannot withdraw from nor drop the course.

Grading

Submission Rules

The deadline is Friday, March 26 at 11:59PM Eastern. If your last submission is on Wednesday, March 24 by 11:59PM, you will receive a 5% bonus. If your last submission is on Thursday, March 25 by 11:59PM, you will receive a 2.5% bonus.

Remember that we grade your BEST submission for style. If multiple submissions are tied in score, we take the last of those.

WARNING: Beware the autograder’s ability to detect cheating! See Collaboration Policy for further information.

Working with a Partner

Distribution Code

Download the distribution code using this link. After unzipping, you’ll find these files:

utility.h A header file with declarations (aka prototypes) of the helper functions you’ll have to implement.

utility.cpp
Implementations of functions declared in utility.h.

caesar.h
A header file with declarations of the functions related to caesar cipher you’ll have to implement.

caesar.cpp
Implementations of functions declared in caesar.h.

vigenere.h
A header file with declarations of the functions related to vigenere cipher you’ll have to implement.

vigenere.cpp
Implementations of functions declared in vigenere.h.

polybius.h
A header file with declarations of the functions related to polybius cipher you’ll have to implement.

polybius.cpp
Implementations of functions declared in polybius.h.

ciphers.cpp
A function that allows the user to encrypt and decrypt messages. This file uses functions from utility.h, caesar.h, vigenere.h, polybius.h.

start.cpp
A program that allows you to select between executing your tests in test.cpp and using the ciphers you have created.

Additionally, you’ll be working with this file that you’ll have to create yourself:

test.cpp
A test suite for functions declared in utility.h, caesar.h, vigenere.h, polybius.h. Its job is to reveal bugs that someone (e.g. you or staff) could have made while implementing those functions. All testing should be done by printing to the standard output. Note that there will be no main function in this file.

NOTE: The starter code will not compile until you:

Suggested Timeline

As an approximate timeline, you will be on track if by:

Warm-up

To make working on this project easier and more fun, be sure you’re able to answer the following questions:

Getting Started

Multiple Files

Creating a Project

Writing Function Stubs

Test Suite

Creating test.cpp

List of Functions to Test

Here the a list of functions you will need to test in test.cpp.

Submit Frequently

Bugs To Expose

There are a total of 13 unique bugs to find in our implementations. Your tests do not need to expose all of the bugs to receive full points for the lab. The autograder will tell you the names of the bugs that you have exposed, from the following set:

Helper functions

After your code compiles, your next task in this project is to indulge in writing functions in utility.cpp. These functions will serve as helper functions in caesar.cpp, vigenere.cpp, and polybius.cpp Remember to write your testing function for each function before you write the function itself. For example, write test_toUppercase() (in test.cpp) before you write the implementation of toUpperCase().

toUpperCase()

string toUpperCase(string original);

removeNonAlphas()

string removeNonAlphas(string original);

removeDuplicate()

string removeDuplicate(string original);

charToInt()

int charToInt(char original);

Ciphers

IMPORTANT: As you implement the functions in the next section, you will find it helpful to refer to the Function Table linked at the bottom of the spec. The table contains the relationship between the functions below, i.e., which functions are called by others.

Art of Cryptography

caesar.cpp

Cæsar

NOTE: Most of this project’s specification has been encrypted with a key of 26, which is twice as secure as a key of 13.[1]

shiftAlphaCharacter()

char shiftAlphaCharacter(char c, int n);

caesarCipher()

string caesarCipher(string original, int key, bool encrypt);

IMPORTANT: Don’t forget to keep writing tests in test.cpp for functions we declared in caesar.h!

vigenere.cpp

Vigenère

vigenereCipher()

string vigenereCipher(string original, string keyword, bool encrypt);

polybius.cpp

Polybius Square

grid decrypt

IMPORTANT: Note that the grid does not represent any non-alphanumerical character. This means that such characters cannot be encrypted, unlike the Caeser and Vigenere cipher. However spaces are allowed in the plaintext, and should be represented as spaces in the ciphertext.

fillGrid()

void fillGrid(char grid[SIZE][SIZE], string content);

mixKey()

string mixKey(string key);

findInGrid()

string findInGrid(char c, char grid[SIZE][SIZE]);

polybiusSquare()

string polybiusSquare(char grid[SIZE][SIZE], string key, string original, bool encrypt);

IMPORTANT: Note that spaces are allowed in the original message, and they must stay as spaces in the encrypted message as well.

ciphers.cpp

WARNING: Sanity check! At this point, utility.cpp, caesar.cpp, vigenere.cpp, and polybius.cpp should have implementations of all functions that we declared in utility.h, caesar.h, vigenere.h, and polybius.h, and test.cpp should have a test suite for those functions. If you have not yet submitted, we highly encourage you to do so, unless you are starting late and it is close to the deadline so you have few submissions remaining.

Overview

WARNING: Be sure not to modify any of the header files, since we’ll be using the original version when grading your project.

Error handling

Here are the errors you must handle:

Sample Output

When you run ciphers.cpp, it should behave per the examples below. Assume that the red underlined text is what some user has typed.

NOTE: The following sample runs do not include the menu selection detailed in Creating a Project.

Choose a cipher (Caesar, Vigenere, or Polybius): caesar
Encrypt or decrypt: encrypt
Enter a message: I solemnly swear that I am up to no good.
What is your key: 7
The encrypted message is: P zvsltusf zdlhy aoha P ht bw av uv nvvk.

Choose a cipher (Caesar, Vigenere, or Polybius): c
Encrypt or decrypt: e
Enter a message: I solemnly swear that I am up to no good.
What is your key: 7
The encrypted message is: P zvsltusf zdlhy aoha P ht bw av uv nvvk.

Choose a cipher (Caesar, Vigenere, or Polybius): vigenere
Encrypt or decrypt: decrypt
Enter a message: U lgp'a os qaoxitk iaz ltvcfqq. Teoafoq ckwhtpd riady qh.
What is your key: Mischief managed.
The decrypted message is: I don't go looking for trouble. Trouble usually finds me.

Choose a cipher (Caesar, Vigenere, or Polybius): ViGenere
Encrypt or decrypt: DECrypt
Enter a message: U lgp'a os qaoxitk iaz ltvcfqq. Teoafoq ckwhtpd riady qh.
What is your key: Mischief managed.
The decrypted message is: I don't go looking for trouble. Trouble usually finds me.

Choose a cipher (Caesar, Vigenere, or Polybius): polybius
Encrypt or decrypt: encrypt
Enter a message: EECS 183 is the best
What is your key: POLYBIUS
The encrypted message is: 15151311 435445 0511 332215 04151133

Choose a cipher (Caesar, Vigenere, or Polybius): P
Encrypt or decrypt: E
Enter a message: EECS 183 is the best
What is your key: polybius
The encrypted message is: 15151311 435445 0511 332215 04151133

Choose a cipher (Caesar, Vigenere, or Polybius): hello
Invalid cipher!

Choose a cipher (Caesar, Vigenere, or Polybius): C
Encrypt or decrypt: V
Invalid mode!

Choose a cipher (Caesar, Vigenere, or Polybius): v
Encrypt or decrypt: e
Enter a message: EECS 183 is the best
What is your key: 183
Invalid key!

Choose a cipher (Caesar, Vigenere, or Polybius): p
Encrypt or decrypt: e
Enter a message: EECS 183 is the best!
Invalid message!

IMPORTANT: Note that when selecting Polybius Square, the decrypted message is all uppercase, while the original message contained lower case letters. This is fine, as the grid we construct only supports uppercase letters.

Function Table

WARNING: The table below does not include all cases of where to use the helper functions from utility.cpp. There are hints in the specification where to use your helper functions, and you should consider implementing these functions first.

File Function Other functions it should call
utility.cpp toUpperCase() Does not utilize any other functions
utility.cpp removeNonAlphas() Does not utilize any other functions
utility.cpp charToInt() Does not utilize any other functions
utility.cpp removeDuplicate() Does not utilize any other functions
caesar.cpp shiftAlphaCharacter() Does not utilize any other functions
caesar.cpp caesarCipher() shiftAlphaCharacter()
vigenere.cpp vigenereCipher() toUpperCase(), removeNonAlphas(), shiftAlphaCharacter()
polybius.cpp mixKey() removeDuplicate()
polybius.cpp fillGrid() Does not utilize any other functions
polybius.cpp findInGrid() Does not utilize any other functions
polybius.cpp polybiusSquare() mixKey(), fillGrid(), findInGrid(), charToInt()

Here is an example of how to read the table:

NOTE: Note that the functions under “Other functions it should call” only refer to the functions you will implement. Feel free to use library functions anywhere.

Style Checklist

To maximize your style points, be sure to follow this non-exhaustive checklist:

NOTE: We will not be grading style in test.cpp.

How to Submit

NOTE: The file names must match exactly as listed above.

IMPORTANT: Be sure to submit all parts of the project (including test.cpp).

WARNING: Ensure that you’ve included your (and your partner’s) name, your (and your partner’s) uniqname and a small description of the program in the header comments.

IMPORTANT: Both partners’ names and uniqnames must be in the header comments in all files submitted.

NOTE: Differences in whitespace will fail the autograder.

S’More Functionality

OPTIONAL: For more practice and fun, check out the S’More for Project 3. With this optional challenge you can implement the functions in decrypt.cpp to break encryption.

[1] http://www.urbandictionary.com/define.php?term=ROT26

[2] http://www.independent.co.uk/life-style/history/42-the-answer-to-life-the-universe-and-everything-2205734.html