Question
Write a program that asks the user if they want to encrypt or decrypt, to supply a key, and either the plaintext or ciphertext depending
Write a program that asks the user if they want to encrypt or decrypt, to supply a key, and either the plaintext or ciphertext depending on their choice to encrypt or decrypt. The program will store the user supplied string in a character vector. After which it will send the choice to encrypt/decrypt, the key, and the vector to a function that will encrypt or decrypt appropriately. Only one function will be needed for this program. Its functionality will change depending on the first parameter.
#include
#include
#include
using namespace std;
int main()
{
vector
string w;
int key;
char choice;
cout << "Welcome to the ceaser salad cipher machine" << endl;
cout << "Would you like to (E)ncrypt or (D)ecrypt: ";
cin >> choice;
if (choice == 'e')
{
cout << " Enter key: ";
cin >> key;
cin.clear();
cin.ignore();
cout << " Enter your plaintext: ";
getline(cin, w);
text.push_back(w);
}
else
{
if (choice == 'd')
{
cout << " Enter key: ";
cin >> key;
cin.clear();
cin.ignore();
cout << "Enter your ciphertext";
getline (cin, w);
text.push_back(w);
}
}
return 0;
}
void cipher(vector
{
if (b == 'e')
{
for (int i = 0, n = t.size; i < n; i++)
{
if (isalpha(t.[i]))
{
//if character is a letter, assume it is an upper case
//ASCI 65 = 'A'
int offset = 65;
//if character is a lowercase letter, offset it by 97
//ASCI 97 = 'a'
if (islower(t.[i]))
offset = 97;
//formula to encrypt the letter by the key
int cipheredLetter = (((int)t.[i] - offset + a) % 26) + offset;
//print out the encrypted character
cout << (char)cipheredLetter;
}
else //if character is not a-z or A-Z, just output it
cout << t.[i];
}
}
if (b == 'd')
{
}
}
This is all I have so far. The problem is i have tried many different ways in doing the cipher but everytime i try i get stopped by the vector.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started