Question: Any new solutions for this program: Vigenre Cipher In this assignment you will be creating a program that is based on the caesar.cpp cipher program

Any new solutions for this program:

Vigenre Cipher

In this assignment you will be creating a program that is based on the caesar.cpp cipher program that was demonstrated in class. This program will enocde and decode text using a Vigenere Cipher -- a technique related to a Caesar Cipher. Your program should have basically the same input and output style as that program, except for a slight change described below. Please don't begin working on this program until you've watched that lecture and studied and understand that example program! Base your design for your program on the design for that program, and you may use any portion of that code that you deem relevant to your project. Follow these direction to create a program named vigenere.cpp, and submit your program in a .zip archive named vigenere.zip.

In this program, you will create a program to do encoding and decoding of messages using the Vignere cipher. A Vigenere cypher is very similar to the Caeser cipher discussed in class, except that instead of using a single numeric value to shift each letter (we used three in the example program,) you use a series of values whre those values are determined by a key word, repeated as many times as necessary to cover each letter of the message. Each letter of the key word applies to one letter of the message, with the key word repeated as many times as necessary to cover the entire length of the message. An "A" in the keyword results in a shift of zero, a "B" shifts a letter by 1, and so on up to "Z" that shifts a letter 25 positions.

For example, if the key word was "ABC" then the first letter of your message would be unchanged, the second letter would be shifted by 1, the third letter by 2, the fourth letter would be unchanged, the fifth letter would be shifted by 1, and so on. See the wikipedia entry at: http://en.wikipedia.org/wiki/Vigenre_cipher for an example of encoding the message "ATTACKATDAWN" with the keyword "LEMON" As in the caesar.cpp program the message to be encoded must only consist of uppercase letters. The keyword will also be only upercase. Whitespace should not alter the encryption, so if you were encoding three words, the output should be the same regardless of the words being entered on one line or three, for example. Your program should have one class named Vigenere, with a similar structure to the Caesar class from the program example. I'll post some sample messages in the class discussion area. Your program should require exactly two command line arugments. The first will either be the code "-e" or "-d" to indicate ecoding or decoding of a message (this determines adding or subtracting you shift values.) and the second paramter will be a single word that will be the keyword that you use for the encryption or decryption.

This assignment is very similar to the Caeser cipher and this is caeser cipher:

#include #include #include

using namespace std;

class Caesar{ public: Caesar(int shamt); // specify shift amount string encrypt(string); string decrypt(string); string simplify(string); private: char shift(char, int); int shamt; };

Caesar::Caesar(int shiftAmount){ shamt = shiftAmount; }

// precondition: plaintext is UPPERCASE letters only string Caesar::encrypt(string plaintext){ string ciphertext=""; int size = plaintext.size(); for(int i=0; i< size; i++){ ciphertext = ciphertext + shift(plaintext[i], shamt); } return ciphertext; }

// precondition: plaintext is UPPERCASE letters only string Caesar::decrypt(string ciphertext){ string plaintext=""; int size = ciphertext.size(); for(int i=0; i< size; i++){ plaintext = plaintext + shift(ciphertext[i], -shamt); } return plaintext; }

// return edited copy of string with only UPPERCASE letters string Caesar::simplify(string text){ string simplified=""; int size = text.size(); for(int i=0; i

char Caesar::shift(char c, int shamt){ // cout << " char was:" << c << " with value:" << c -'A' << endl; int result = (c-'A'+shamt);

if (result >= 26) result = result - 26; if (result < 0) result = result + 26; return result+'A'; }

int main(int argc, char *argv[]){

/* cout << "argc is " << argc << endl; for(int i = 0; i< argc; i++){ cout << i << ": " << argv[i] << endl; } */

if (argc != 3){ cerr << "USAGE: " << argv[0] << " -d|e shiftAmount" << endl; exit(1); } int shamt = atoi( argv[2] ); bool encrypt; string option( argv[1]); string line; string encodedLine; if (option == "-e"){ encrypt = true; } else { encrypt = false; } Caesar cipher(shamt); while( getline(cin, line) ){ if (encrypt){ encodedLine = cipher.encrypt(cipher.simplify(line)); } else { encodedLine = cipher.decrypt(line); } cout << encodedLine << endl; } return 0; }

How to base on caeser program to write the Vigenre Cipher program? you must use C++

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!