Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 text;

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 t, int &a, char &b)

{

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Relational Database And SQL

Authors: Lucy Scott

3rd Edition

1087899699, 978-1087899695

More Books

Students also viewed these Databases questions

Question

The process of selling a promissory note. True/False

Answered: 1 week ago

Question

Explain the function and purpose of the Job Level Table.

Answered: 1 week ago