Question
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":
- Functions can only take pointers as arguments.
- The array subscript operator [] may not be used to access or modify the contents of an array.
- Reference variables may not be used.
- With the exception of main, all functions must be void functions.
- 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:
- 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.
- 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.
- msg_len points to the number of characters in msg and key_len points to the number of characters in key.
- 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
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
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