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
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
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 = "Run the Jewels Live at the Garden!"; char encrypted_message; 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
vigenere_cipher are provided below.
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
chardatatype on the iesc.io compiler is a signed 8-bit number, meaning the largest number that can be stored in a
In the next checker, you will have access to a functioning implementation of
\ / /\__/\ \__=( o_O )= (__________) |_ |_ |_ |_Course Site powered by CAT-SOOP 14.0.4.dev5.