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
Will mark Brainliest, need help ASAP!
Whitepunk [10]

Answer:

What Sherman needs to configure is:

RIPv2 class D of 240.

Explanation:

Multicast messages are usually dispatched to a select group of hosts on a network and require acknowledgement of the recipients. RIPv2 is a router-based internet protocol for exchanging routing information to the IP address 224.0. 0.9 on a network. It determine the most efficient way to route data on a network and to prevent routing loops.

3 0
2 years ago
Which are advantages of using a server operating system?
iogann1982 [59]

Answer:

Extra security features and networking services built right in

Explanation:

The major advantage of using a server operating system is that it has decent security features and networking services built right in it from the default settings

8 0
2 years ago
True or false mobile devices need to work within limited screen space
eduard
A phone may have a 4 inch screen and so it cant just extend to 5 inches. So it would he true
3 0
2 years ago
Read 2 more answers
Write a program that computes the minimum, maximum, average and standard deviation of the population over time for a borough (en
IrinaK [193]

Answer:

import pandas as pd #importing pandas library as pd

import matplotlib.pyplot as plt #importing matplotlib.pyplot as plt

pop=pd.read_csv('nycHistPop.csv') #reading the csv file

borough=input('Enter borough name:') #asking the user for borough namme

# image=input('Enter image name:')

# pop['Fraction']=pop[borough]/pop['Total']

# pop.plot(x='Year', y='Fraction')

print("Minimum population",pop[borough].min()) #printing the minimum population of borough

print("Maximum population",pop[borough].max()) #printing the maximum population of borough

print("Average population",pop[borough].mean()) #printing the average population of borough

print("Standard deviation",pop[borough].std()) #printing the standard deviation of borough

# fig=plt.gcf()

# fig.savefig(image)

Explanation:

4 0
3 years ago
What was the impetus for corporations to begin entertainment broadcasting on radio?
Sladkaya [172]

To help radio operators on ships stay awake was the impetus for corporations to begin entertainment broadcasting on radio.

e. to help radio operators on ships stay awake

<u>Explanation:</u>

The principal radio station ever on the planet's history was made by Reginald Fessenden on Christmas Eve in 1906 when he radiated a "Christmas show" to the bewildered teams of the boats of the United Fruit Company out in the Atlantic Ocean and the Caribbean Sea.

The main voice and music signals heard over radio waves were transmitted in December 1906 from Brant Rock, Massachusetts (only south of Boston), when Canadian experimenter Reginald Fessenden delivered about an hour of talk and music for specialized onlookers and any radio beginners who may be tuning in.

Radio turned into another type of correspondence and amusement. Between the 1920s and 1950s many radio shows were communicated, and assembling around the radio at night was a typical type of diversion.

4 0
3 years ago
Other questions:
  • Name size of machine screw that is used to secure switches and receptacles to device boxes
    13·1 answer
  • ____ are systems in which queues of objects are waiting to be served by various servers
    5·1 answer
  • How many water bottles must be collected to win?
    8·2 answers
  • What are the factors affecting the purchasing decision for dbms software?
    7·2 answers
  • Explain the saying "Dress for the position you want, not the position you have."
    6·2 answers
  • 1.Terry turned on his computer one day to find that all of the storage on his computer was filled up. Furthermore, there were ma
    6·1 answer
  • Write a algorithm to attend birthday party​
    8·2 answers
  • Which operating system function has a steeper learning curve and can potentially break the system without careful use of its ope
    7·1 answer
  • What is faster C++ or go lang
    15·1 answer
  • Explain any two features of a computer​
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!