1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
icang [17]
3 years ago
7

Implement the RC4 stream cipher in C++. User should be able to enter any key that is 5 bytes to 32 bytes long. Be sure to discar

d the first 3072 bytes of the pseudo random numbers. THE KEY OR THE INPUT TEXT MUST NOT BE HARD CODED IN THE PROGRAM.
Computers and Technology
1 answer:
gladu [14]3 years ago
6 0

Answer:

Explanation:

#include <iostream>

#include <string>

#include<vector>

using namespace std;  

vector<int> permute(vector<int>, vector<int>);

string encrypt(vector<int>s1 , vector<int> t1, string p);

string decrypt(vector<int>s1, vector<int> t1, string p);

int main() {

  string plaintext = "cryptology";

  string plaintext2 = "RC4";

  vector<int> S(256);

  vector<int> T(256);

  int key[] = { 1,2,3,6 };

  int key2[] = { 5,7,8,9 };

  int tmp = 0;

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

      S[i] = i;

      T[i] = key[( i % (sizeof(key)/sizeof(*key)) )];

  }

  S = permute(S, T);

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

      cout << S[i] << " ";

      if ((i + 1) % 16 == 0)

          cout << endl;

  }

  cout << endl;

  string p = encrypt(S, T, plaintext);

  cout << "Message: " << plaintext << endl;

  cout << "Encrypted Message: " << " " << p << endl;

  cout << "Decrypted Message: " << decrypt(S, T, p) << endl << endl;

  tmp = 0;

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

      S[i] = i;

      T[i] = key2[(i % (sizeof(key) / sizeof(*key)))];

  }

  S = permute(S, T);

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

      cout << S[i] << " ";

      if ((i + 1) % 16 == 0)

          cout << endl;

  }  

  cout << endl;

  p = encrypt(S, T, plaintext2);

  cout << "Message: " << plaintext2 << endl;

  cout << "Encrypted Msg: " << p << endl;

  cout << "Decrypted Msg: "<<decrypt(S, T, p) << endl << endl;

  return 0;

}

string decrypt(vector<int>s1, vector<int> t1, string p) {

  int i = 0;

  int j = 0;

  int tmp = 0;

  int k = 0;

  int b;

  int c;

  int * plain = new int[p.length()];

  string plainT;

  for (int r = 0; r < p.length(); r++) {

      i = (i + 1) % 256;

      j = (j + s1[i]) % 256;

      b = s1[i];

      s1[i] = s1[j];

      s1[j] = b;

      tmp = (s1[i] + s1[j]) % 256;

      k = s1[tmp];

      c = ((int)p[r] ^ k);

      plain[r] = c;

      plainT += (char)plain[r];

  }

  return plainT;

}  

string encrypt(vector<int>s1, vector<int> t1, string p) {

  int i = 0;

  int j = 0;

  int tmp = 0;

  int k = 0;

  int b;

  int c;

  int * cipher = new int [p.length()];

  string cipherT;

  cout << "Keys Generated for plaintext: ";

  for (int r = 0; r < p.length(); r++) {

      i = (i + 1) % 256;

      j = (j + s1[i]) % 256;

      b = s1[i];

      s1[i] = s1[j];

      s1[j] = b;

      tmp = (s1[i] + s1[j]) % 256;

      k = s1[tmp];

      cout << k << " ";

      c = ((int)p[r] ^ k);

      cipher[r] = c;  

      cipherT += (char)cipher[r];

  }

  cout << endl;

  return cipherT;

}

vector<int> permute(vector<int> s1, vector<int> t1) {

  int j = 0;

  int tmp;

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

      j = (j + s1[i] + t1[i]) % 256;

      tmp = s1[i];

      s1[i] = s1[j];

      s1[j] = tmp;

  }

  return s1;

}

You might be interested in
What are the six primary roles that information system play in organizations? How are information system used in each context
Nina [5.8K]

The primary roles that information system play in organizations are:

  • Decision making
  • Operational management
  • Customer interaction
  • Collaboration on teams
  • Strategic initiatives
  • Individual productivity
<h3>How are information system used in each context</h3>

The six main functions of information systems in an organization are as follows:

1. Operational management entails the creation, maintenance, and enhancement of the systems and procedures utilized by businesses to provide goods and services.

2. Customer relationship management: Maintaining positive and fruitful relationships with customers, clients, students, patients, taxpayers, and anyone who come to the business to purchase goods or services is essential for success. Effective customer relationships contribute to the success of the business.

3. Making decisions: Managers make decisions based on their judgment. Business intelligence is the information management system used to make choices using data from sources other than an organization's information systems.

4. Collaboration and teamwork: These two skills complement the new information systems that allow people to operate from anywhere at a certain moment. Regardless of their position or location, individuals can participate in online meetings and share documents and applications.

5. Developing a competitive edge: A firm can establish a competitive advantage by outperforming its rival company and utilizing information systems in development and implementation.

6. Increasing productivity of objection: Smart phone applications that mix voice calls with online surfing, contact databases, music, email, and games with software for minimizing repetitive tasks are tools that can help people increase productivity.

Learn more about information system from
brainly.com/question/14688347
#SPJ1

4 0
11 months ago
Arrange the code so that the numbers are swapped.
Ahat [919]
Rand.int(your_num , your_num
5 0
2 years ago
Which of these about non-disclosure agreements is accurate?
grandymaker [24]

Answer: number 2

Explanation: number 2

6 0
2 years ago
Read 2 more answers
How many channels can the 2.4 GHz band be divided into?
wlad13 [49]

Answer:Fourteen channels

Explanation:

8 0
2 years ago
Briefly describe the role of creativity and innovation to entrepreneurship​
prisoha [69]

Answer:

isia

Explanation:

Apooopooopeeepepe

8 0
2 years ago
Other questions:
  • Question 4 (2 points)
    6·2 answers
  • What conclusion did Freud reach when attempting to understand the connection between psychological and physical problems?
    12·1 answer
  • Online databases allow you access to material you may not be able to find when using popular search engines like Google. Select
    10·1 answer
  • Omega Software Inc. is currently running a training program for employees to upgrade their software skills so that they are able
    10·1 answer
  • dam is writing a program that: 1) has the user guess a number, and 2) tells the user how many guesses it took to get the correct
    9·1 answer
  • A web designer is creating a web site and wants each browser to resize the text size to look the same in each device. what measu
    6·1 answer
  • Two categories of payroll deductions are required deductions and ___ deductions.
    9·2 answers
  • ___are designed to infect and cause damage to operating system files, computer registry, and other locations on the motherboard
    15·1 answer
  • Agent Phil Coulson developed this program to register Avengers in S.H.I.E.L.D's database using cutting-edge programming language
    15·1 answer
  • A wireless ________ extender is a network device that enhances transmission of your wireless signal.
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!