Hello. I need help changing the C++ code so that the highlighted portions are can be entered by the user. See the attached picture for clarity. Thank you. #include #include

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

Hello. I need help changing the C++ code so that the highlighted portions are can be entered by the user. See the attached picture for clarity. Thank you.

#include <iostream>

#include <iomanip>

 

#define swap(v1, v2, temp) temp = v1, v1 = v2, v2 = temp;

 

using namespace std;

 

inline void generateRC4SBox(uint8_t s[256] /*=sbox*/, const uint8_t* key, int keylength)

{

    for(int i = 0; i < 256; i++)

        s[i] = i;

 

    uint8_t j = 0, swap;

 

    for(int i = 0; i < 256; i++)

    {

        j += s[i] + key[i % keylength]; //The addition is in fact modulo 256

        swap(s[i], s[j], swap); //Exchange s[i] and s[j]

    }

}

 

inline void RC4(const uint8_t* message, uint8_t* cipher, int start, int stop, uint8_t s[256] /*=sbox*/)

{

    uint8_t i = 0, j = 0, swap;

 

    for(int n = start; n < stop; n++)

    {

        j += s[++i]; //Note that i is effectively increased by one before the rest is evaluated

        swap(s[i], s[j], swap); //Exchange s[i] and s[j]

        if(message && cipher)

            cipher[n] = s[(uint8_t)(s[i]+s[j])]^message[n]; //Cast inside [..] is needed!

    }

}

 

int main(int, char**)

{

    const uint8_t *key = (uint8_t *)"66OlSO8L7KoW44awcg2xHJ9X1FbOoF4z", *message = (uint8_t *)"Plaintext";

    const int key_length = 32, message_length = 9; //I do not include terminating 0 character. One might as well include it.

    uint8_t sbox[256], *cipher = new uint8_t[message_length];

 

    cout<<"RC4 ENCRYPTION"<<endl<<endl<<"preparing sbox (key scheduling) with password \""<<key<<"\"..."<<endl;

    generateRC4SBox(sbox, key, key_length);

 

    cout<<"skipping first 3072 bytes and encrypting..."<<endl<<endl;

    RC4(0, 0, 0, 3072, sbox); //"Fast forward by 3072 bytes" = "encrypt nonexistent data"

    RC4(message, cipher, 0, message_length, sbox); // The actual encryption is done here.

 

    cout<<"MESSAGE: "; for(int n = 0; n < message_length; n++) cout<<hex<<setw(2)<<(int)message[n]<<' '; cout<<" (=\""<<message<<"\")"<<endl;

    cout<<"CIPHER:  "; for(int n = 0; n < message_length; n++) cout<<hex<<setw(2)<<(int) cipher[n]<<' '; cout<<endl;

 

    delete[] cipher; //Standard cleanup for data allocated on the heap

    cipher = 0;

 

    return 0;

}

int main(int,
{
const uint8_t *key
*message =
|const int key_length = 32, message_length = 9; //I do not include
terminating 0 character. One might as well include it.
uint8_t sbox[256], *cipher
char**)
(uint8_t *)"660lS08L7KoW44awcg2xHJ9X1Fb0oF4z",
(uint8_t *)"Plaintext";
new uint8_t[message_length];
Transcribed Image Text:int main(int, { const uint8_t *key *message = |const int key_length = 32, message_length = 9; //I do not include terminating 0 character. One might as well include it. uint8_t sbox[256], *cipher char**) (uint8_t *)"660lS08L7KoW44awcg2xHJ9X1Fb0oF4z", (uint8_t *)"Plaintext"; new uint8_t[message_length];
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Structure chart
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education