Question: my code encodes and decodes like this Test VigenereForwardIterator First phrase: To be , or not to be: that is the question: Encoded text:

my code encodes and decodes like this
Test VigenereForwardIterator
First phrase: "To be, or not to be: that is the question:"
Encoded text: "Lt nf, ia ccm lt nf: nqph bk ytf kdtgmatz"
Decoded text: "To be, or not to be: that is the question"
Second phrase: "Be cool"
when i need it to do this
Test VigenereForwardIterator
First phrase: "To be, or not to be: that is the question:"
Encoded text: "Lt nf, ia ccm lt nf: nqph bk ytf kdtgmatz:"
Decoded text: "To be, or not to be: that is the question:"
Second phrase: "Be cool"
Encoded text: "Tj opiu"
Decoded text: "Be cool"
Third phrase: ""
Encoded text: ""
Decoded text: "" done
and also YOU ARE NOT ALLOWED TO CHANGE THE P2 AT ALL, ONLY THE VIGERENEFORWARDITERATOR.CPP
VIGERENEFORWARDITERATOR.CPP
void VigenereForwardIterator::encodeCurrentChar() noexcept {
if (fKeys != fKeys.end()){
char messageChar = fSource[fIndex];
if (std::isalpha(messageChar)){
char keywordChar =*fKeys;
if (!std::isalpha(keywordChar)||!std::isupper(keywordChar)){
fCurrentChar = messageChar;
return;
}
size_t row = static_cast(keywordChar -'A');
if (row >= CHARACTERS){
fCurrentChar ='?';
return;
}
size_t column = static_cast(std::toupper(messageChar)-'A');
char encodedChar = fMappingTable[row][column];
if (std::islower(messageChar)){
encodedChar = std::tolower(encodedChar);
}
fCurrentChar = encodedChar;
++fKeys;
}
else {
fCurrentChar = messageChar;
}
}
}
void VigenereForwardIterator::decodeCurrentChar() noexcept {
if (fKeys != fKeys.end()){
char messageChar = fSource[fIndex];
if (std::isalpha(messageChar)){
char keywordChar =*fKeys;
if (!std::isalpha(keywordChar)||!std::isupper(keywordChar)){
fCurrentChar = messageChar;
return;
}
size_t row = static_cast(keywordChar -'A');
size_t column =0;
while (column < CHARACTERS && fMappingTable[row][column]!= std::toupper(messageChar)){
++column;
}
if (column < CHARACTERS){
int decodedCharInt ='A'+ static_cast(column);
char decodedChar = static_cast(decodedCharInt);
if (std::islower(messageChar)){
decodedChar = std::tolower(decodedChar);
}
fCurrentChar = decodedChar;
++fKeys;
}
else {
fCurrentChar = messageChar;
}
}
else {
fCurrentChar = messageChar;
}
}
}
P2 that is in my main, do not edit
#ifdef P2
void runP2()
{
gCount++;
std::cout << "Test VigenereForwardIterator" << std::endl;
std::string lKey = "Relations";
std::string lPhrase1="To be, or not to be: that is the question:";
std::cout << "First phrase: \""<< lPhrase1<<"\""<< std::endl;
std::string lEncoded1;
VigenereForwardIterator iter1(lKey, lPhrase1);
for (; iter1!= iter1.end(); ++iter1)
{
lEncoded1+=*iter1;
}
std::cout << "Encoded text: \""<< lEncoded1<<"\""<< std::endl;
std::string lDecoded1;
VigenereForwardIterator iter2(lKey, lEncoded1, EVigenereMode::Decode);
for (; iter2!= iter2.end(); iter2++)
{
lDecoded1+=*iter2;
}
std::cout << "Decoded text: \""<< lDecoded1<<"\""<< std::endl;
std::string lPhrase2="Be cool";
std::cout << "Second phrase: \""<< lPhrase2<<"\""<< std::endl;
std::string lEncoded2;
for (char c : VigenereForwardIterator(lKey, lPhrase2))
{
lEncoded2+= c;
}
std::cout << "Encoded text: \""<< lEncoded2<<"\""<< std::endl;
std::string lDecoded2;
for (char c : VigenereForwardIterator(lKey, lEncoded2, EVigenereMode::Decode))
{
lDecoded2+= c;
}
std::cout << "Decoded text: \""<< lDecoded2<<"\""<< std::endl;
std::string lPhrase3="";
std::cout << "Third phrase: \""<< lPhrase3<<"\""<< std::endl;
std::string lEncoded3;
for (char c : VigenereForwardIterator(lKey, lPhrase3))
{
lEncoded3+= c;
}
std::cout << "Encoded text: \""<< lEncoded3<<"\""<< std::endl;
std::string lDecoded3;
for (char c : VigenereForwardIterator(lKey, lEncoded3, EVigenereMode::Decode))
{
lDecoded3+= c;
}
std::cout << "Decoded text: \""<< lDecoded3<<"\""<< std::endl;
std::cout << "done" << std::endl;
}

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 Programming Questions!