Question: Using C++, write a program to implement the Vigenre cipher. important: Please create a class for the letters to do the overload, like: class Letter

Using C++, write a program to implement the Vigenre cipher.

important: Please create a class for the letters to do the overload, like:

class Letter {

public:

friend Letter operator+(const Letter &lhs, const Letter &rhs);

private:

char c;

};

Then use a vector of Letter to store the plaintext/ciphertext/key.

Vonvert between this and a std::string, loop through each element and convert.

a actor of Letter that takes a char to getter to go back to a string.

Example of pseudocode:

Letter to offset:

if (isupper(letter)) {

return letter - A

} else {

return letter - a

}

To encrypt a single letter (this should be part of the overloaded + operator):

ciphertext_offset = (letter_to_offset(plaintext_letter) + letter_to_offset(key_letter)) % 26

if (isupper(plaintext_letter)) {

return ciphertext_letter + A

} else {

return ciphertext_letter + a

}

To decrypt a single letter (this should be part of the overloaded - operator):

plaintext_offset = (letter_to_offset(ciphertext_letter) - letter_to_offset(key_letter) + 26) % 26

if (isupper(ciphertext_letter)) {

return plaintext_offset + A

} else {

return plaintext_offset + a

}

To encrypt a string:

key_letter = 0

for each character c of the plaintext {

if (c is not an alphabetic character) {

ciphertext += c

} else {

ciphertext += c + key[key_letter]

++key_letter

key_letter %= key.length()

}

}

To decrypt a string:

key_letter = 0

for each character c of the ciphertext {

if (c is not an alphabetic character) {

plaintext += c

} else {

plaintext += c - key[key_letter]

++key_letter

key_letter %= key.length()

}

}

-------------------------------------------------------------------------------------

Plaintext: How vexingly quick daft zebras jump! Key: KEY KEYKEYKE YKEYK EYKE YKEYKE YKEY Ciphertext: Rsu fivsrevc oemau hypx xofpkw heqn!

-------------------------------------------------------------------------------------

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!