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 discard the first 3072 bytes of the pseudo random numbers. THE KEY OR THE INPUT TEXT MUST NOT BE HARD CODED IN THE PROGRAM.

Answers

Answer 1
Answer:

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;

}


Related Questions

Plz answer me will mark as brainliest ​
Add CSS rules to articles.css for the given news article webpage that matches the following styling: Both article's images styled with a width of 300px Article's tag styled with: 5px padding all around Font family of Arial Font size of 24px Font color of white Background color of red. Selecting the id of author-name-and-date, style the author name and date with: Font family of Arial Font size of 12px Font color of lightgray Article's text ( and tags) styled with: Font family of Times New Roman Font size of 16px Font color of gray Article's share links ( tags) styled with: Font family of Arial Font size of 12px Font color of blue Note: Colors, font sizes, padding, etc. must be exact.
____ produces a full-featured, working model of the information system. A. Loose coupling B. Fourth-generation modeling C. System prototyping D. Web servicing
Write a program that accepts a four digit number, such as 1998, and displays it on number on a line, like: 1 9 9 8 The program should prompt for a four digit number. The program assumes that the user enters the correct information. Provide the java code, including a comment with your name, course code and date.
Write a function named minMax() that accepts three integers arguments from the keyboard and finds the smallest and largest integers. Include the function minMax() in a working program. Make sure your function is called from main().Test the function by passing various combinations of three integers to it.

Write a program (main method) that advises the user on programming language. So if a user for instance enters "Java" the program might say "awesome" or if the user enters "Ruby" it might say "are you sure?" . Make the program comment on at least 5 programming languages.

Answers

import java.util.Scanner;

public class JavaApplication41 {

   

   public static void main(String[] args) {

       Scanner scan = new Scanner(System.in);

       String language = scan.nextLine();

       if (language.toLowerCase().equals("java")){

           System.out.println("Awesome!");

       }

       else if (language.toLowerCase().equals("python")){

           System.out.println("A very simple language!");

       }

       else if (language.toLowerCase().equals("ruby")){

           System.out.println("Are you sure?");

       }

       else if (language.toLowerCase().equals("javascript")){

           System.out.println("Easy enough");

       }

       else if (language.toLowerCase().equals("c")){

           System.out.println("Cool!");

       }

   }

   

}

I hope this helps!

Who could vote in the first democracy?A.
Everyone
B.
Citizens
C.
Adults
D.
Women

Answers

Correct Answer: citizens

What is the main purpose of the status report? O A. To ensure that management and the team has a clear picture of the state of the project. B. To alert management to exceptional or unusual situations, C. To document the impact of change requests from the client. D. To detail the mistakes made in planning and budgeting,​

Answers

Answer:

A. To ensure that management and the team has a clear picture of the state of the project

Explanation:

hope this helps!

Answer:

A

Explanation:

Consider the method total below:public static int total (int result, int a, int b){ if (a == 0) { if (b == 0) { return result * 2; } return result / 2; } else { return result * 3; }}
The assignment statementx = total (1, 1, 1);must result in:A. x being assigned the value 3 B. x being assigned the value 7C. x being assigned the value 5D. x being assigned the value 2E. x being assigned the value 0

Answers

Answer:

Explanation:



When you look at the assignment "x = total (1, 1, 1);", you can see that result, a and b all refers to 1. Then, you need to go to the function and check the conditions. The first condition is "if (a == 0)", it is not true because a is assigned to 1. Since that is not true, you need to go to the else part "else { return result * 3". That means the result of this function is going to give us 3 (because result variable equals to 1 initially). That is why x is going to be assigned as 3.

________ is a hybrid version of Ethernet that uses either 10Base-T, 100Base-T, or 1000Base-T. a. Mullion Ethernet
b. Base-T Ethernet
c. 10/100/1000 Ethernet
d. Token ring Ethernet
e. FDDI Ethernet

Answers

Answer: ANSWER is B I'm pretty sure

Explanation: hope this help

s :)

For each of the following algorithms medicate their worst-case running time complexity using Big-Oh notation, and give a brief (3-4 sentences each) summary of the worst-case running time analysis. (a) Construction of a heap of size n , where the keys are not known in advance.
(b) Selection-sort on a sequence of size n.
(c) Merge-sort on a sequence of size n.
(d) Radix sort on a sequence of n integer keys, each in the range of[ 0, (n^3) -1]
(e) Find an element in a red-black tree that has n distinct keys.

Answers

Answer:

Answers explained below

Explanation:

(a) Construction of a heap of size n , where the keys are not known in advance.

Worst Case Time complexity - O(n log n)

Two procedures - build heap, heapify

Build_heap takes O(n) time and heapify takes O(log n) time. Every time when an element is inserted into the heap, it calls heapify procedure.

=> O(n log n)

(b) Selection-sort on a sequence of size n.

Worst Case Time complexity - O(n^2)

Selection sort finds smallest element in an array repeatedly. So in every iteration it picks the minimum element by comparing it with the other unsorted elements in the array.

=> O(n^2)

(c) Merge-sort on a sequence of size n.

Worst Case Time complexity - O(n log n)

Merge sort has two parts - divide and conquer. First the array is divided (takes O(1) time) into two halves and recursively each half is sorted (takes O(log n) time). Then both halves are combines (takes O(n) time).

=> O(n log n)

(d) Radix sort on a sequence of n integer keys, each in the range of[ 0 , (n^3) -1]

Worst Case Time complexity - O (n log b (a))

b - base of the number system, a - largest number in that range, n - elements in array

Radix sort is based on the number of digits present in an element of an array A. If it has 'd' digits, then it'll loop d times.

(e) Find an element in a red-black tree that has n distinct keys.

Worst Case Time complexity - O (log n)

Red-black tree is a self-balancing binary tree => The time taken to insert, delete, search an element in this tree will always be with respect to its height.

=> O(log n)