Question

Implement the RC4 algorithm. Suppose the key consists of the following seven bytes: (OxlA, 0x2B, 0x3C,...

Implement the RC4 algorithm. Suppose the key consists of the following seven bytes: (OxlA, 0x2B, 0x3C, 0x4D, 0x5E, 0x6F, 0x77). For each of the following, give S in the form of a 16 x 16 array where each entry is in hex. I am supposed to create a java code to get the output and answer the questions.

a. List the permutation S and indices i and j after the initialization phase has completed.

b. List the permutation S and indices i and j after the first 100 bytes of keystream have been generated.

c. List the permutation S and indices i and j after the first 1000 bytes of keystream have been generated

Homework Answers

Answer #1

/*I came up with the below plain to cipher change algorithm .

*I think it can be useful.

*/

import java.io.* ;
import java.util.Scanner;
class rc4 {
public static void main(String args[]) throws IOException
{
int temp = 0;
String ptext;
String key;
int s[] = new int[256];
int k[] = new int[256];
Scanner in =new Scanner(System.in );
System.out.print("\nENTER PLAIN TEXT\t");
ptext = in.nextLine();
System.out.print("\n\nENTER KEY TEXT\t\t");
key = in.nextLine();
char ptextc[] = ptext.toCharArray();
char keyc[] = key.toCharArray();
int cipher[] = new int[ptext.length()];
int decrypt[] = new int[ptext.length()];
int ptexti[] = new int[ptext.length()];
int keyi[] = new int[key.length()];
  
for (int i = 0; i < ptext.length(); i++)
{
ptexti[i] = (int) ptextc[i];
}
for (int i = 0; i < key.length(); i++)
{
keyi[i] = (int) keyc[i];
}
for (int i = 0; i < 255; i++)
{
s[i] = i;
k[i] = keyi[i % key.length()];
}
int j = 0;
for (int i = 0; i < 255; i++)
{
j = (j + s[i] + k[i]) % 256;
temp = s[i];
s[i] = s[j];
s[j] = temp;
}
int i = 0;
j = 0;
int z = 0;
for (int l = 0; l < ptext.length(); l++) {
i = (l + 1) % 256;
j = (j + s[i]) % 256;
temp = s[i];
s[i] = s[j];
s[j] = temp;
z = s[(s[i] + s[j]) % 256];
cipher[l] = z ^ ptexti[l];
decrypt[l] = z ^ cipher[l];
}
System.out.print("\nENCRYPTED:\t");
display(cipher);
System.out.print("\nDECRYPTED:\t");
display(decrypt);
}
static void display(int disp[]) {
char convert[] = new char[disp.length];
for (int l = 0; l < disp.length; l++)
{
convert[l] = (char) disp[l];
System.out.print(convert[l]);
}
System.out.println("");
}
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
1. Given an n-element array A, Algorithm X executes an O(n)-time computation for each even number...
1. Given an n-element array A, Algorithm X executes an O(n)-time computation for each even number in A and an O(log n)-time computation for each odd number in A. What is the best-case running time of Algorithm X? What is the worst-case running time of Algorithm X? 2. Given an array, A, of n integers, give an O(n)-time algorithm that finds the longest subarray of A such that all the numbers in that subarray are in sorted order. Your algorithm...
Please create a python module named homework.py and implement the functions outlined below. Below you will...
Please create a python module named homework.py and implement the functions outlined below. Below you will find an explanation for each function you need to implement. When you are done please upload the file homework.py to Grader Than. Please get started as soon as possible on this assignment. This assignment has many problems, it may take you longer than normal to complete this assignment. This assignment is supposed to test you on your understanding of reading and writing to a...
Hi there, I've been asked to write a program in C which can read values from...
Hi there, I've been asked to write a program in C which can read values from a file then sort them, and then write to a binary file. I'm getting stuck when I write my binary file as the output is just spitting out garbage values and not the values that are being read in. When I print my input file reader everything is perfect but after sorting and then writing, the output is completely wrong. I have checked that...
Java question, Please answer everything. Thank you Answer the following questions as briefly (but completely) as...
Java question, Please answer everything. Thank you Answer the following questions as briefly (but completely) as possible: What is a checked exception, and what is an unchecked exception? What is NullPointerException? Which of the following statements (if any) will throw an exception? If no exception is thrown, what is the output? 1: System.out.println( 1 / 0 ); 2: System.out.println( 1.0 / 0 ); Point out the problem in the following code. Does the code throw any exceptions? 1: long value...
Consider the C program (twoupdate) to demonstrate race condition. In this assignment, we will implement Peterson's...
Consider the C program (twoupdate) to demonstrate race condition. In this assignment, we will implement Peterson's algorithm to ensure mutual exclusion in the respective critical sections of the two processes, and thereby eliminate the race condition. In order to implement Peterson's Algorithm, the two processes should share a boolean array calledflagwith two components and an integer variable called turn, all initialized suitably. We will create and access these shared variables using UNIX system calls relating to shared memory – shmget,...
Modify the following code by JAVA language Write a static method totalDurations that is passed the...
Modify the following code by JAVA language Write a static method totalDurations that is passed the parallel arrays from the main program. It creates a new pair of parallel arrays (phone numbers and durations, again) where each different incoming phone number is stored exactly once, and the duration is the total duration of all the calls from that phone number. It then prints these arrays. Nothing is returned. For example, if the arrays contain 555-1234 (duration 10), 555-4321 (duration 20),...
Objectives:The focus of this assignment is to create and use a recursive method given a moderately...
Objectives:The focus of this assignment is to create and use a recursive method given a moderately difficult problem. Program Description: This project will alter the EmployeeManager to add a search feature, allowing the user to find an Employee by a substring of their name. This will be done by implementing the Rabin-Karp algorithm. A total of seven classes are required. Employee (From previous assignment) HourlyEmployee (From previous assignment) SalaryEmployee (From previous assignment) CommissionEmployee (From previous assignment) EmployeeManager (Altered from previous...
1) Describe an example of each of the following that may be found of your kitchen:...
1) Describe an example of each of the following that may be found of your kitchen: Explain how your choice falls into this category, and if there is a chemical name or symbol for it, provide that as well. Provide a photo of your example with your ID card in it. a) a compound b) a heterogeneous mixture c) an element (symbol) Moving to the Caves… Lechuguilla Caves specifically. Check out this picture of crystals of gypsum left behind in...
Laboratory 4: Black Jack! Java API ArrayList Lab 04 Documentation Included matrix package "external" documentation Included...
Laboratory 4: Black Jack! Java API ArrayList Lab 04 Documentation Included matrix package "external" documentation Included Download Lab04.zip for all of the additional supporting files that you will need to compile and run. Extract the files into your working directory You can find the rules of blackjack all over the Internet. To get an idea of what you are trying to accomplish in this lab, I’ll demonstrate the final solution. The dealer stands on all 17s. Doubling after splitting is...
Objective: The student will apply course objectives through evaluating patient assessments, identifying treatment options and developing...
Objective: The student will apply course objectives through evaluating patient assessments, identifying treatment options and developing teaching plans for patients with obesity, peptic ulcer disease (PUD) and gastroesophageal reflux disease (GERD). Part I: Obesity & Bariatric Surgery A 32-year-old obese patient has come to the bariatric outpatient center to have an initial evaluation. The patient reports that they were always overweight, even as a child. The patient states that they are frustrated because they gained 100 pounds over the last...