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
Impact of information technology in the society​
GarryVolchara [31]

Answer:

led to exposure of dangerous things

3 0
2 years ago
If you want to conserve ink or toner, you can instruct PowerPoint to print ____ documents.
kondor19780726 [428]
I believe the answer would be Draft Quality. (300x300 resolution).

5 0
3 years ago
A numeric test score is to be converted to a letter grade of A, B, or C according to the following rules: A score greater than 9
arlik [135]

The code segment makes use of conditional statements.

Conditional statements in programming are used to make decisions

The code segment in C++ is as follows

if (score > 90) {

grade = 'A';

}

else if (score >= 80 && score < =90) {

grade = 'B';

}

else {

grade = 'C';

}

The above code segments take the score, make comparison, and then determine the appropriate letter grade.

Read more about code segments at:

brainly.com/question/20475581

7 0
2 years ago
In addition to key executives, there are other positions in a company that may be considered critical, or whose loss will be dif
Otrada [13]

Answer:

Explanation:

Every employee who works for a company plays an important role in his field. some of the key employees of a company is sales representative, marketing executives, human resource managers, etc

whereas in manufacturing sector additional employees are developers, manufacturing workers, quality testers, etc, which when leaves a company, there is always a chance for the employee to join the competitors which is a threat to integrity of a company

Plus particular field becomes unstable for that time until a good employee hire again for the same position.

If a network administrator leaves, the company may suffer from their network issues. as a network administrator maintain networks, troubleshoot with any network problem, checks the security of the network and many more, he plays a very important role in the company.

If a sales representative leaves the job from the company, sometimes it results as a great loss of a company as a sales representative is in direct contact with customers, and when they leave a job there are chances that they carry the customer with them which results in loss of business.

5 0
2 years ago
Which of the following plug-ins was developed by microsoft and is a software development tool used to write and run internet app
Elodia [21]
I'm not a hundred percent sure but maybe silverlight?
5 0
3 years ago
Other questions:
  • Given num_rows and num_cols, print a list of all seats in a theater. Rows are numbered, columns lettered, as in 1A or 3E. Print
    7·1 answer
  • What are the main types of computer software?
    5·2 answers
  • Print a countdown from n to 1 The function below takes one parameter: an integer (begin). Complete the function so that it print
    8·1 answer
  • Describe the following types of data hazards. RAW WAR WAW
    13·1 answer
  • What is the Most popular game out today?
    6·2 answers
  • A powerboat is about to cross paths with a sailboat under sail. What should the powerboat do
    5·1 answer
  • All of the following are helpful tips for protecting your digital privacy, except:
    10·2 answers
  • Desirable workplace habits and skills include:
    14·1 answer
  • WILL MARK BRAINLIEST!!!!!!!!!!!
    6·2 answers
  • What is a system of access control that allows only limited use of material that has been legally purchased?
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!