Caesar_Vigenere II

Spring 2019

The questions below are due on Sunday March 31, 2019; 11:59:00 PM.
 
You are not logged in.

If you are a current student, please Log In for full access to the web site.
Note that this link will take you to an external site (https://oidc.mit.edu) to authenticate, and then you will be redirected back to this page.

Back to Exercise 07

1) Once more, with C++!!

On the previous page we wrote a Python implementation of our Vigenere/Caesar Cipher. We'll now write a C++ version so that we can take care of both sides of our system as needed (embedded and server side). Just like with Python, we'll have two functions caesar_cipher and vigenere_cipher, except some pieces of them will need to be different. We're defining our two C++ functions in such a way that neither of them return anything. Instead, we'll need to utilize a reference to a String object value passed in as our output for both the caesar_cipher and vigenere_cipher. This means that, for example, with the Caesar Cipher, the function definition will look like the following:

void caesar_cipher(char* message_in, char* message_out, int shift, bool encrypt, int out_buffer_size)

If we were to use it we'd need to hand it a reference to a proper NULL-terminated char-array in the following form:

char message_to_encrypt[50] = "Run the Jewels Live at the Garden!";
char encrypted_message[50];
int shift = 7;
caesar_cipher(message_to_encrypt,encrypted_message,shift,true,sizeof(encrypted_message));
//encrypted_message holds our encrypted message

The primary difference between this implementation and the Python implementation on the previous page, is the need to specify how large the output buffer is. In the case where the output buffer is smaller than the input length of the input char array, the code must fill the output buffer to its maximum valid size, but no more.

Test cases for the C++ versions of caesar_cipher and vigenere_cipher are provided below.

Note that if you are getting UTF-8 errors, Your code produced invalid outputs, or something similar it most likely means you are indexing outside of the valid range of ascii chars. Look up how the % operator works in C++—it is not the same as in Python! We repeat. It is not the same as Python. It is also worth noting that a char datatype on the iesc.io compiler is a signed 8-bit number, meaning the largest number that can be stored in a char is 127.

void caesar_cipher(char* message_in, char* message_out, int shift, bool encrypt, int out_buffer_size){ //your code here }

In the next checker, you will have access to a functioning implementation of caesar_cipher.

void vigenere_cipher(char* message_in, char* message_out, char* keyword, bool encrypt, int out_buffer_size){ //your code }

Back to Exercise 07



This page was last updated on Wednesday March 20, 2019 at 05:39:59 PM (revision 024d95c).
 
Course Site powered by CAT-SOOP 14.0.4.dev5.
CAT-SOOP is free/libre software, available under the terms
of the GNU Affero General Public License, version 3.
(Download Source Code)
CSS/stryling from the Outboxcraft library Beauter, licensed under MIT
Copyright 2017