Below is the question. Below is the question. Below is the starter code. Below i
ID: 3722415 • Letter: B
Question
Below is the question. Below is the question.Below is the starter code.
Below is the grading rubric.
I do not want the same answer used that was used for another question posted on here. Will give thumbs up for correct answer. PA5: Decrypting a secret message In this assignment, you'll decrypt a secret message using a cipher. A "cipher is a program that converts a message in normal text into a secret message, and vice-versa. For example, the normal message .meet at five pm" might be converted to the secret message·l@@. (#c@ r using a cipher. The secret message can be sent to a friend. Nobody else could read the message, expect the friend whose cipher would convert the secret message back to normal text. The starter program decrypts the first character in a secret message if that first character is The complete list of cipher and normal characters to decrypt a message: 'S
Explanation / Answer
decrypt_1.cpp
-----------------------------------
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(){
vector<char> normalV(26);
vector<char> cipherV(26);
string toDec = "";
string beenDec = "";
normalV.at(0) = 'n'; cipherV.at(0) = '{';
//Get secret Message
do{
cout << "Enter a secret message: ";
getline(cin, toDec);
}while(toDec.length() == 0);
beenDec = toDec;
//Decrypt secret message
if(toDec.at(0) == cipherV.at(0)){
beenDec.at(0) = normalV.at(0);
}
cout << "Decrypted Message : " << beenDec << endl;
return 0;
}
-------------------------------------------------------
decrypt_2.cpp
-------------------------------------------------
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(){
vector<char> normalV(26);
vector<char> cipherV(26);
string toDec = "";
string beenDec = "";
normalV.at(0) = 'n'; cipherV.at(0) = '{';
normalV.at(1) = 'c'; cipherV.at(1) = '&';
normalV.at(2) = 'e'; cipherV.at(2) = '@';
normalV.at(3) = 'i'; cipherV.at(3) = '#';
//Get secret Message
do{
cout << "Enter a secret message: ";
getline(cin, toDec);
}while(toDec.length() == 0);
beenDec = toDec;
//Decrypt secret message
for(int i=0; i<normalV.size(); i++){
for(int j=0; j<toDec.length(); j++){
if(toDec.at(j) == cipherV.at(i)){
beenDec.at(j) = normalV.at(i);
}
}
}
cout << "Decrypted Message : " << beenDec << endl;
return 0;
}
---------------------------------------------
decrypt_3.cpp
-------------------------------------------
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(){
vector<char> normalV(26);
vector<char> cipherV(26);
string toDec = "";
string beenDec = "";
normalV.at(0)='a'; cipherV.at(0)='!';
normalV.at(1)='b'; cipherV.at(1)='^';
normalV.at(2)='c'; cipherV.at(2)='&';
normalV.at(3)='d'; cipherV.at(3)='*';
normalV.at(4)='e'; cipherV.at(4)='@';
normalV.at(5)='f'; cipherV.at(5)='(';
normalV.at(6)='g'; cipherV.at(6)=')';
normalV.at(7)='h'; cipherV.at(7)='-';
normalV.at(8)='i'; cipherV.at(8)='#';
normalV.at(9)='j'; cipherV.at(9)='_';
normalV.at(10)='k'; cipherV.at(10)='=';
normalV.at(11)='l'; cipherV.at(11)='+';
normalV.at(12)='m'; cipherV.at(12)='[';
normalV.at(13)='n'; cipherV.at(13)='{';
normalV.at(14)='o'; cipherV.at(14)='$';
normalV.at(15)='p'; cipherV.at(15)=']';
normalV.at(16)='q'; cipherV.at(16)='}';
normalV.at(17)='r'; cipherV.at(17)=';';
normalV.at(18)='s'; cipherV.at(18)=':';
normalV.at(19)='t'; cipherV.at(19)=',';
normalV.at(20)='u'; cipherV.at(20)='%';
normalV.at(21)='v'; cipherV.at(21)='<';
normalV.at(22)='w'; cipherV.at(22)='.';
normalV.at(23)='x'; cipherV.at(23)='>';
normalV.at(24)='y'; cipherV.at(24)='/';
normalV.at(25)='z'; cipherV.at(25)='?';
//Get secret Message
do{
cout << "Enter a secret message: ";
getline(cin, toDec);
}while(toDec.length() == 0);
beenDec = toDec;
//Decrypt secret message
for(int i=0; i<normalV.size(); i++){
for(int j=0; j<toDec.length(); j++){
if(toDec.at(j) == cipherV.at(i)){
beenDec.at(j) = normalV.at(i);
}
}
}
cout << "Decrypted Message : " << beenDec << endl;
return 0;
}
---------------------------------------
Test Runs:
-------------------------------------------
$ g++ decrypt_1.cpp
$ ./a.out
Enter a secret message: {#&@
Decrypted Message : n#&@
$ g++ decrypt_2.cpp
$ ./a.out
Enter a secret message: {#&@
Decrypted Message : nice
$ g++ decrypt_3.cpp
$ ./a.out
Enter a secret message: {#&@
Decrypted Message : nice
$ ./a.out
Enter a secret message: [@@, !, (#<@ ][
Decrypted Message : meet at five pm
$ ./a.out
Enter a secret message: Y$% -!<@ ${&@ !)!#{ ($#+@* [/ ]+!{:
Decrypted Message : You have once again foiled my plans
$
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.