Question: n c++. Implement .h and .cpp files for the following UMLS : 3.1.1 Cipher The Cipher class is an abstract class that describes the basic

n c++. Implement .h and .cpp files for the following UMLS :

3.1.1 Cipher

The Cipher class is an abstract class that describes the basic interface of any cipher. This is

an interface class, i.e. it provides no implementation.

Create the Cipher class in a file called

Cipher.h according to the UML specification below:

Cipher

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

+encode(const string&): string

+decode(const string&): string

cipher is an algorithm that can encode plaintext, turning it into ciphertext, as well as decode

ciphertext, turning it back into plaintext. Abstract Cipher declares two pure virtual functions:

string encode(const string&) This function is abstract and must be overridden by the

derived classes. The function will receive plaintext (string) as input, encrypt it, and return

encrypted ciphertext (string).

string decode(const string&) This function is abstract and must be overridden by the

derived classes. The function will receive ciphertext (string) as input, decode it, and

return decoded plaintext (string).

3.1.2 SubstitutionCipher

In cryptography, a substitution cipher is a method of encryption that replaces individual units

of plaintext with ciphertext, according to a predefined pattern. For this task, consider "units"

of text to be single characters. Substitution ciphers will thus encode and decode text by encoding/

decoding each character of text individually.

The Cipher interface can be extended to create an abstract SubstitutionCipher class, which

will become the base class for all concrete substitution ciphers. Create the SubstitutionCipher

class in SubstitutionCipher.h and SubstitutionCipher.cpp files, according to the UML and the

specifications below.

SubstitutionCipher

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

+encode(const string&): string

+decode(const string&): string

#encode(char):char

#decode(char):char

Since characters are going to be encrypted and decrypted individually, two protected functions

can be added to the SubstitutionCipher class:

char encodeChar(char) This function is abstract (pure virtual) and must be overridden by

the derived classes. The function will receive a plaintext character (char) as input, encrypt

it, and return ciphertext character (char).

char decodeChar(char) This function is abstract (pure virtual) and must be overridden

by the derived classes. The function will receive a ciphertext character (char) as input,

decode it, and return plaintext character (char).

The functions are protected because the user is expected to interact with the class via the

inherited public interface of the parent class (Cipher). The abstract functions inherited from

the parent class Cipher can be overidden and implemented now:

string encode(const string&) This function receives plaintext (string) as input, encrypts

it by applying encodeChar function to each character of plaintext, and returns the ciphertext

(string).

string decode(const string&) This function receives ciphertext (string) as input, decodes

it by applying decodeChar to every character of ciphertext, and returns plaintext

(string).

Note that the SubstitutionCipher is still an abstract class, because it has two pure virtual functions.

However, it does implement some of the functionality according to the interface of the

Cipher class. The non-abstract encode and decode functions make use of the abstract encodeChar

and decodeChar functions. When a child class implements encodeChar and decodeChar as prescribed

by the SubstitutionCipher, the SubstitutionCipher will already know how to apply these

functions to plaintext and ciphertext. Such interaction between the classes in the hierarchy allows

for modular design and distributed implementation, making it a well-known object-oriented

design pattern. This design pattern is known as the Template Method pattern.

.1.3 Vigenere

The Vigenre cipher is named after Blaise de Vigenre (1523-1596), and it is a simple cipher

where each letter in the plaintext is replaced with a letter corresponding to a certain number of

letters up or down in the alphabet. The exact shift for each letter is determined by a secret

codeword: the distance from the first letter of the alphabet to each letter of the codeword

determines the shift.

For example, suppose the secret codeword is BAD. We can calculate how far each character

is from the beginning of the alphabet: B is the second letter in the Latin alphabet, thus it is 1

position away from the beginning (A). A is the first letter, so the distance from the beginning

is zero. Finally, D is the fourth letter in the alphabet, thus the distance from A is 3. Therefore,

BAD corresponds to the following shifts: 1, 0, 3. Lets apply these shifts to the word CAT.

First, align the plaintext with the codeword and see what shifts have to be applied:

C A T
B A D
1 0 3

So C has to be moved forward by 1 character. Thus, C will be replaced by D (next letter in

the alphabet). A aligns with A, and because A is already at the beginning of the alphabet,

no shift will be applied. T has to be moved forward by 3 characters, and if you remember the

Latin alphabet, you would know the 3rd letter after T is W. Thus, the encyption for CAT is

DAW:

plaintext: C A T
codeword: B A D
shifts 1 0 3

ciphertext:

D A W

home / study / engineering / computer science / computer science questions and answers / in c++. implement .h and .cpp files for the following umls : 3.1.1 cipher the cipher class ...

Your question has expired and been refunded.

We were unable to find a Chegg Expert to answer your question.

Question: In c++. Implement .h and .cpp files for the following UMLS : 3.1.1 Cipher The Cipher class is an ...

In c++. Implement .h and .cpp files for the following UMLS :

3.1.1 Cipher

The Cipher class is an abstract class that describes the basic interface of any cipher. This is

an interface class, i.e. it provides no implementation.

Create the Cipher class in a file called

Cipher.h according to the UML specification below:

Cipher

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

+encode(const string&): string

+decode(const string&): string

cipher is an algorithm that can encode plaintext, turning it into ciphertext, as well as decode

ciphertext, turning it back into plaintext. Abstract Cipher declares two pure virtual functions:

string encode(const string&) This function is abstract and must be overridden by the

derived classes. The function will receive plaintext (string) as input, encrypt it, and return

encrypted ciphertext (string).

string decode(const string&) This function is abstract and must be overridden by the

derived classes. The function will receive ciphertext (string) as input, decode it, and

return decoded plaintext (string).

3.1.2 SubstitutionCipher

In cryptography, a substitution cipher is a method of encryption that replaces individual units

of plaintext with ciphertext, according to a predefined pattern. For this task, consider "units"

of text to be single characters. Substitution ciphers will thus encode and decode text by encoding/

decoding each character of text individually.

The Cipher interface can be extended to create an abstract SubstitutionCipher class, which

will become the base class for all concrete substitution ciphers. Create the SubstitutionCipher

class in SubstitutionCipher.h and SubstitutionCipher.cpp files, according to the UML and the

specifications below.

SubstitutionCipher

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

+encode(const string&): string

+decode(const string&): string

#encode(char):char

#decode(char):char

Since characters are going to be encrypted and decrypted individually, two protected functions

can be added to the SubstitutionCipher class:

char encodeChar(char) This function is abstract (pure virtual) and must be overridden by

the derived classes. The function will receive a plaintext character (char) as input, encrypt

it, and return ciphertext character (char).

char decodeChar(char) This function is abstract (pure virtual) and must be overridden

by the derived classes. The function will receive a ciphertext character (char) as input,

decode it, and return plaintext character (char).

The functions are protected because the user is expected to interact with the class via the

inherited public interface of the parent class (Cipher). The abstract functions inherited from

the parent class Cipher can be overidden and implemented now:

string encode(const string&) This function receives plaintext (string) as input, encrypts

it by applying encodeChar function to each character of plaintext, and returns the ciphertext

(string).

string decode(const string&) This function receives ciphertext (string) as input, decodes

it by applying decodeChar to every character of ciphertext, and returns plaintext

(string).

Note that the SubstitutionCipher is still an abstract class, because it has two pure virtual functions.

However, it does implement some of the functionality according to the interface of the

Cipher class. The non-abstract encode and decode functions make use of the abstract encodeChar

and decodeChar functions. When a child class implements encodeChar and decodeChar as prescribed

by the SubstitutionCipher, the SubstitutionCipher will already know how to apply these

functions to plaintext and ciphertext. Such interaction between the classes in the hierarchy allows

for modular design and distributed implementation, making it a well-known object-oriented

design pattern. This design pattern is known as the Template Method pattern.

3.1.3 Vigenere

The Vigenre cipher is named after Blaise de Vigenre (1523-1596), and it is a simple cipher

where each letter in the plaintext is replaced with a letter corresponding to a certain number of

letters up or down in the alphabet. The exact shift for each letter is determined by a secret

codeword: the distance from the first letter of the alphabet to each letter of the codeword

determines the shift.

For example, suppose the secret codeword is BAD. We can calculate how far each character

is from the beginning of the alphabet: B is the second letter in the Latin alphabet, thus it is 1

position away from the beginning (A). A is the first letter, so the distance from the beginning

is zero. Finally, D is the fourth letter in the alphabet, thus the distance from A is 3. Therefore,

BAD corresponds to the following shifts: 1, 0, 3. Lets apply these shifts to the word CAT.

First, align the plaintext with the codeword and see what shifts have to be applied:

C A T
B A D
1 0 3

So C has to be moved forward by 1 character. Thus, C will be replaced by D (next letter in

the alphabet). A aligns with A, and because A is already at the beginning of the alphabet,

no shift will be applied. T has to be moved forward by 3 characters, and if you remember the

Latin alphabet, you would know the 3rd letter after T is W. Thus, the encyption for CAT is

DAW:

plaintext: C A T
codeword: B A D
shifts 1 0 3

ciphertext:

D A W

To decode, the process is reversed: ciphertext letters are aligned with the codeword, and

the codeword shifts are subtracted from the ciphertext, i.e. the letters are shifted backwards:

ciphertext:

D A W
codeword: B A D
shifts: 1 0 3
plaintext: C A T

What if your text is longer than the codeword? Well, you can always just apply the codeword

repetitively:

ciphertext: H E L L O
codeword (repeated): B A D B A
shifts: 1 0 3 1 0
plaintext: I E O M O

IEOMO sounds nothing like HELLO, thus you can consider the text to be encrypted.

In C++, all characters correspond to integer ASCII values, which makes char type very convenient

to work with: to shift a character upwards or backwards, you can simply add the necessary

integer shift value to the character, or subtract a shift value from the character. You are also

allowed to subtract the characters from each other, or add them to one another. The following

code is valid in C++:

char plainChar = H;

int shift = 2;

char cipherChar = plainChar + shift; / / encrypt a character

char decodeChar = cipherChar - shift; / / decode a character

Implement the Vigenere class according to the UML and the specifications below:

Vigenere

-codeword: string

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

+Vigenere(const string&)

+setCodeword(const string&): void

+encode(const string&): string

+decode(const string&): string

#encode(char):char

#decode(char):char

The Vigenere class has a private member codeword:

string codeword The codeword used for encoding/decoding, as described earlier.

The Vigenere class has the following member functions:

Vigenere(const string&) Parameterised constructor that sets the codeword to the provided

string.

void setCodeword(const string&) public function that allows the user to set the codeword

to another string. This function must handle invalid input using exceptions. For this

purpose, create the Exception class in a file called Exception.h according to the following

UML:

Exception

#error:string

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

+Exception(const string&)

+getError(): string

The Exception object is initialised with an error message, and provides the getError()

function to return the error message. You will be using various error messages for various

exceptions throughout this assignment. Thus, you may consider extending the Exception

class for various types of exceptions. However, please note that all Exception-related code

should be placed in Exception.h. DO NOT create a separate .cpp file.

The codeword should only be accepted if it is more than one character long, and if it is not

made entirely of (space) characters. The space character (ASCII code 32) is the first

printable character in the given range, thus a codeword made entirely of spaces would result

in shifts of zero, and the text will not be encrypted. If the codeword is either too short,

or made out of spaces, throw an Exception object initialised with the following message:

The codeword provided is not going to generate a safe encryption. The message should

contain no punctuation and no new line characters.

char encodeChar(char) this function implements Vigenre encoding. A plaintext char is

received as input and shifted according to the current place in the codeword. The shifted

char is returned. No error-checking has to be done in this function.

char decodeChar(char) this function implements Vigenre decoding. A ciphertext char is

received as input, and the decoded char is returned. No error-checking has to be done in

this function.

Note that encode(string) and decode(string) are also listed in the UML. You may override

these functions if you need to add extra functionality to them. Remember that child classes

have access to the base class implementations for the purpose of code re-use.

Vigenere class is not an abstract class, therefore you can instantiate a Vigenere object and test

your code. Test your encoding thoroughly before submitting for marking! Here are some examples

for different codewords:

{{ Hello World! }} plaintext

>=Ni4./1Nx>4/&OAL? ciphertext, codeword = BANANA

oac;KaUcJUgJdrcr ciphertext, codeword = secret

I]s=K_:Yn<=TYfrKg ciphertext, codeword = MasterMind

Make sure you can always successfully recover the original plaintext message.

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!