Ask Question
29 May, 10:50

Write a program that encrypts and decrypts a string of characters. Use a char array for this, not the string class. The maximum length of a string input to the program will be 200 characters. The input may contain blanks and other whitespace. Your program must request a c-string from the user and encrypt it as described below. If the user enters a single asterisk as the only thing on a line, the program should stop. Otherwise, encrypt the string, then display the encrypted version. Decrypt it using the inverse of the algorithm below and display the result. This should be the original string. Then go back and request another string.

+3
Answers (1)
  1. 29 May, 13:57
    0
    C+ + code for encryption is given below

    Explanation:

    #include

    using namespace std;

    //functions to encrypt and decrypt

    void encrypt (char str[]);

    void decrypt (char str[]);

    int main () {

    char str[200];

    bool done = false;

    while (! done) {

    cout << "Enter a string (enter * to stop) : ";

    cin. getline (str, 200);

    if (str[0] = = '*' && str[1] = = '/0')

    done = true;

    else{

    encrypt (str);

    cout << "Encrypted: " << str << endl;

    decrypt (str);

    cout << "Decrypted: " << str << endl;

    }

    cout << endl;

    }

    }

    void encrypt (char str[]) {

    int i = 1;

    for (int j = 0; str[j]! = '/0'; j++) {

    str[j] + = i;

    i++;

    if (i = = 11)

    i = 1;

    }

    }

    void decrypt (char str[]) {

    int i = 1;

    for (int j = 0; str[j]! = '/0'; j++) {

    str[j] - = i;

    i++;

    if (i = = 11)

    i = 1;

    }

    }
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Write a program that encrypts and decrypts a string of characters. Use a char array for this, not the string class. The maximum length of a ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers