Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

My question is how to create this function within my program (It has me stumped, still figuring out pointers) where encrypt_letter and decrypt_letter are calls

My question is how to create this function within my program (It has me stumped, still figuring out pointers) where encrypt_letter and decrypt_letter are calls to other functions named: void encrypt_letter(char* letter, const char* key); and void decrypt_letter(char* letter, const char* key); While following these "restrictions":

  1. Functions can only take pointers as arguments.
  2. The array subscript operator [] may not be used to access or modify the contents of an array.
  3. Reference variables may not be used.
  4. With the exception of main, all functions must be void functions.
  5. The C++ string class can not be used to store plaintext, keywords, or ciphertext. Instead use arrays of characters.

Here is the function:

  • void shift_message(char *msg, const int *msg_len, const char *key, const int *key_len, const int *mode) - does the following:
    1. If *mode is zero, use encrypt_letter to replace the plaintext in the array pointed to by msg with the corresponding ciphertext using the keyword pointed to by key.
    2. If *mode is one, use decrypt_letter to replace the ciphertext in the array pointed to by msg with the corresponding plaintext using the keyword pointed to by key.
    3. msg_len points to the number of characters in msg and key_len points to the number of characters in key.
    4. Only uppercase letters should be replaced. Leave all other characters alone.

Hint: use a separate index to keep track of which keyword letter you are using, and advance it every time to encrypt/decrypt a letter. When the index reaches *key_len, set it to zero to go back to the beginning.

and here is my program so far if it helps with context:

#include #include using namespace std;

const int MAX_SIZE = 256; const int MAX_KEY = 16; const int ENCRYPT_CODE = 0; const int DECRYPT_CODE = 1;

void displayMenu() { cout << "1. Encrypt a plaintext message" << endl; cout << "2. Decrypt a ciphertext message" << endl; cout << "3. Exit" << endl; } void read_string(char* str, const int* max_len, int* len) { char Character; *len = 0; cin.get(Character);

while (Character != ' ') {

if (Character < *max_len - 1) {

*(str + *len) = '\0'; *len++; }

cin.get(Character); }

} void encrypt_letter(char* letter, const char* key) {

} void decrypt_letter(char* letter, const char* key) {

} void shift_message(char* msg, const int* msg_len, const char* key, const int* key_len, const int* mode) {

}

int main() {

int choice = 0; char messageArray[MAX_SIZE]; char keyArray[MAX_KEY]; int message_length = 0; int key_length = 0;

do {

displayMenu(); cin >> choice;

//validate if (!(choice >= 1 && choice <= 3)) { do { cout << "Invalid choice" << endl; displayMenu(); cin >> choice; } while (!(choice >= 1 && choice <= 3)); }

switch (choice) { case 1: cout << "Enter a plaintext message: "; //method read_string cout << "Enter a key"; //method read_string cout << "The encrypted message is: "; cout << endl; break;

case 2: cout << "Enter a ciphertext message: "; cout << endl; //method read_string cout << "Enter a key"; cout << endl; //method read_string cout << "The decrypted message is: "; cout << endl; break;

default: break;

} } while (choice != 3); system("pause"); }

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

Step: 3

blur-text-image

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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2015 Porto Portugal September 7 11 2015 Proceedings Part 2 Lnai 9285

Authors: Annalisa Appice ,Pedro Pereira Rodrigues ,Vitor Santos Costa ,Joao Gama ,Alipio Jorge ,Carlos Soares

1st Edition

3319235249, 978-3319235240

More Books

Students also viewed these Databases questions

Question

Write a Python program to check an input number is prime or not.

Answered: 1 week ago

Question

What are the purposes of collection messages? (Objective 5)

Answered: 1 week ago