please follow the instructions of the assignment properly and do what
Search for question
Question
Please follow the instructions of the assignment properly and do what is asked
while creating appropriate .h and .cpp files.
Need-
C++ code with comments + output screenshots
Submit in the zip file with appropriate headers and cpp files too/n Instructions for submitting the solution
1. Submit the source code file for every programming assignment like .c file, .java file.
2. If any dataset is used then you need to share all the files with solution in a single zip file.
3. Share the readme file in which you have to include the system specification, required
software and the execution instructions.
4. Share the output of the programs. If it is a single program then you can submit the screenshot,
if multiple files are included then please share the screen recording. Below are some steps that
need to be covered in screen recording.
❖ Show the complete solution according to the instructions.
❖ Need to cover all the compilation steps.
Show the complete output of program/project.
Show all pass test cases if given in assignment.
5. Always add proper comments in code. If any specific package is used then please mention it in
comment./n Around 1550 Blaise de Vigenère, a French diplomat from the court of Henry III of France,
developed a new table-based scrambling technique to cipher written language. The technique,
also known as chiffre quarré or chiffre indéchiffrable, was considered safe until the middle of
the 19th century.
The Vigenère Cipher is a polyalphabetic substitution technique based on a mapping table like
the one shown below:
Q
ABCDEFGREUKEN NOPARSTUVWXYN
F G H I J
G H I J K
P
Key Letter A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
с
Ꭰ
B C D E F G H I J K L M N O P Q R S TUVWXYZA
C D E F G H I J K L M N O P Q R S TUVWXYZAB
D E F G H I J K L M N O P Q R S T U V W X Y Z ABC
E F G H I J K L M N O P Q R S T UVWXYZABCD
K L M N O P Q R S T U V W XYZABCDE
L M N O
H I J K L
M N O
P
T
Q R S T U V W X Y Z ABCDEF
Q R S
U V W X Y ZABCDEFG
H
I J K L M N
O
P Q R S T
U V W X Y Z ABCDEFGH
I
J K L M N O
P
Q R S T U
V W X Y Z ABCDEFGHI
J
K L M N O
P
Q R S T
U V W X Y Z ABCDEFGHIJ
L M N O P
Q
R
S T
U
V W X Y Z ABCDEFGHIJK
L
M N O P Q R
S
T U V W X Y Z ABCDEFGHIJKL
M
N O P Q R S
T
U V W X Y Z ABCDEFGHIJKLM
O P Q R S T
U
Т
Z
V W X Y Z ABCDEFGHIJKLMN
P Q R S T U V W X Y Z ABCDEFGHIJKLMNO
Q R S T U V W X Y Z ABCDEFGHIJKLMNOP
R S T U V W X Y Z ABCDEFGHIJKLMNOPQ
STU V W X Y Z ABCDEFGHIJKLMNOPQR
T U V W X Y Z ABCDEFGHIJKLMNOPQRS
U V W X Y Z ABCDEFGHIJKLMNOPQRST
V W X Y Z ABCDEFGHIJKLMNOPQRSTU
W X Y Z ABCDEFGHIJKLMNOPQRSTUV
X Y Z A B C D E F G H I J K L M N O P Q R S T U V W
Y Z A B C D E F G H I J K L M N O P Q R S T U V W X
ZA B C D E F G H I J K L M N O P Q R S T U V W X Y
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
The Vigenère cipher uses this table together with a keyword to encode a message.
To illustrate the use of this encryption method, suppose we wish to scramble the following
message (Hamlet 3/1):
To be, or not to be: that is the question:
using the keyword Relations. First, we notice that the table provides only mappings for
upper case characters. But this is not really a problem. The mapping is identical for upper and
lower case characters. We just rewrite the keyword to consist of upper case characters only.
When encoding a message, we convert each character to an upper case one, perform the
corresponding encryption function, and output the result in either upper case or lower case
depending on the original spelling. All characters not covered in the Vigenère cipher remain
unchanged in the output. No keyword character is consumed in this case!
We begin by writing the keyword. We repeat the keyword until all characters of the input text
are covered. To derive the encoded text using the mapping table, for each letter in the message, one has to find the intersection of the row given by the corresponding keyword
letter and the column given by the message letter itself to pick out the encoded letter.
Keyword:
Message:
Scrambled Message:
RE LA TI ONS RE LA TION SR ELA TIONSREL
To be, or not to be: that is the question:
Lt nf, ia ccm lt nf: ngph bk ytf kdtgmatz:
Decoding of an encrypted message is equally straightforward. One writes the keyword plus
the decoded message:
Keyword:
Scrambled Message:
Decoded Message:
RE LA TI ONS RE LA
Lt nf, ia ccm lt nf:
To be, or not to be:
TION SR ELA TIONSREL
nqph bk ytf kdtgmatz:
that is the question:
This time one uses the keyword letter to pick a row of the table and then traces the row to
the column containing the encoded letter. The index of that column is the decoded letter.
There are many ways to implement the Vigenère cipher. In this midterm, we use two forward
iterators to perform the encoding and decoding of plain English text. The first iterator serves
as keyword provider, whereas the second one implements the Vigenère cipher algorithm for
both encoding and decoding plain English text. Problem 1
(106 marks)
Define a forward iterator, called KeyProvider, that yields a sequence of keyword characters.
A suggested specification of class KeyProvider is shown below:
#pragma once
#include <string>
class KeyProvider
{
private:
std::string fKeys;
size_t fIndex;
std::string preprocessString (const std::string& aString) noexcept; // 18 marks
public:
};
// 32 marks
KeyProvider (const std::string & aKeyword, const std::string& aSource) noexcept;
char operator* () const noexcept; // 4 marks
KeyProvider & operator++() noexcept; // 4 marks
KeyProvider operator++ (int) noexcept; // 10 marks
bool operator= (const KeyProvider & aOther) const noexcept; // 10 marks
bool operator!= (const KeyProvider & aOther) const noexcept; // 4 marks
KeyProvider begin() const noexcept; // 10 marks
KeyProvider end () const noexcept; // 10 marks
The underlying collection for iterator KeyProvider is the string £Keys. The iterator index is
fIndex.
The iterator KeyProvider has to compute the underling collection first. You start with the
keyword, say "Relations", and populate the string fKeys be repeating the keyword, in
upper-case letters, for the length of the message.
Keyword:
Message:
"Relations"
"To be, or not to be: that is the question:"
"RELATIONSRELATIONSRELATIONSREL"
fKeys:
or
Keyword:
Message:
fKeys:
"Relations"
"Be cool"
"RELATI"
Please note, the length of string *Keys equals the number of letters in the message. Only
letters consume keyword characters.
To facilitate the initialization of fKeys, the method preprocessString() can be used.
This method takes a string and returns a new string that consists only of upper-case letters.
For example, preprocessString() applied to "Relations" returns "RELATIONS".
Similarly, if applied to "To be, or not to be: that is the question: ", the method
preprocessString() returns "TOBEORNOTTOBETHATISTHEQUESTION". The implementation of preprocessString() requires the functions isalpha () and
toupper(), both defined in <cctype>.
The constructor of KeyProvider, initializes £Keys and fIndex. The iterator has to be
positioned onto the first element in the underlying collection.
The constructor has to compute the keyword sequence for the input text.
As a security feature, the constructor has to end with an assert statement that guarantees
that the size of fKeys matches the size of the preprocessed input string. The preprocessed
input string may be shorter than aSource.
The dereference operator* () returns the keyword character the iterator is positioned on.
The prefix operator++ () advances the iterator and returns the updated iterator.
The postfix operator++ (int) advances the iterator and returns the old iterator.
The equivalence operator== () returns true if this iterator and aother are equal.
Equivalence requires the same underlying collection and the same position.
The equivalence operator!= () returns true if this iterator and aother are not equal.
The method begin () returns a copy of this iterator positioned at the first keyword
character.
The method end () returns a copy of this iterator positioned after the last keyword
character.
You may test your implementation of KeyProvider using the following test driver (enable
#define P1 in main.cpp).
Running the test driver should produce the following output:
Test KeyProvider
First key sequence: "RELATIONSRELATIONSRELATIONSREL"
Second key sequence: "RELATI"
Third key sequence:
11 11
done Problem 2
(194 marks)
Assume the implementation of KeyProvider is correct.
Using KeyProvider, define the forward iterator VigenerForewardIterator that
satisfies the suggested specification as shown below:
#pragma once
#include <string>
#include "KeyProvider.h"
constexpr size_t CHARACTERS = 26;
enum class EVigenereMode
{
Encode,
};
Decode
class VigenereForwardIterator
{
private:
EVigenereMode fMode;
char fMappingTable [CHARACTERS] [CHARACTERS];
KeyProvider fKeys;
std::string fSource;
size_t fIndex;
char fCurrentChar;
// Initialize the mapping table
// Row 1: B-A
// Row 26: A - Z
void initializeTable();
void encodeCurrentChar() noexcept; // 38 marks
void decodeCurrentChar () noexcept; // 48 marks
public:
};
VigenereForwardIterator(
const std::string& aKeyword,
const std::strings aSource,
EvigenereMode aMode = EVigenereMode::Encode) noexcept; // 26 marks
char operator* () const noexcept; // 2 marks
VigenereForwardIterators operator++ () noexcept; // 14 marks
Vigenere ForwardIterator operator++ (int) noexcept; // 10 marks
bool operator= (const VigenereForwardIterator& aOther) const noexcept; // 10 marks
bool operator!= (const VigenereForwardIterators aOther) const noexcept; // 4 marks
VigenereForwardIterator begin() const noexcept; // 30 marks
VigenereForwardIterator end () const noexcept; // 10 marks
The iterator Vigenere ForwardIterator maintains a cipher mode, a mapping table, a
keyword provider (another iterator), the source text, the current position, and the current
character the iterator has to return.
The constructor has to initialize all member variables with sensible variables. Ideally, all
member variables except fMappingTable should be initialized using member initializers. Use
initializeTable () as the first statement in the constructor to set up the mapping table.
Somebody has already implemented this method: