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...
How to measure the time complexity of an algorithm? Identify an important operation in the algorithm...
How to measure the time complexity of an algorithm? Identify an important operation in the algorithm that is executed most frequently. Express the number of times it is executed as a function of N. Convert this expression into the Big-O notation. A. For each of the three fragments of code, what is its worst-case time complexity, in the form "O(…)". (Use the given solution to the first problem as a model)                 //----------------- This is a sample problem – solved ------...
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...
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...
Using Java, please implement the Poker and PokerHand classes to provide the expected output using the...
Using Java, please implement the Poker and PokerHand classes to provide the expected output using the CardDemo class. Rules are the following: - Deck and PockerHand should be Iterable (note that you may just reuse one of the underlying iterators to provide this functionality) - Poker should implement 2 methods checking for two possible poker hands , see the comments inside the classes for details. Hint: remember how one can count the frequency of words in text? - whenever you...
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,...
Data Structure in C++ I keep getting the same warning, and I cant seem to fix...
Data Structure in C++ I keep getting the same warning, and I cant seem to fix it.. Can you explain to me what I am doing wrong? Warning: dlist.cc: In function 'std::ostream& operator<<(std::ostream&, dlist&)': dlist.cc:66:10: error: invalid initialization of reference of type 'std::ostream& {aka std::basic_ostream&}' from expression of type 'dlist::node*' dlist.cc: In function 'dlist operator+(dlist&, dlist&)': dlist.cc:93:8: error: invalid operands of types 'dlist::node*' and 'dlist::node*' to binary 'operator+' dlist.cc:97:8: error: could not convert 'result' from 'int' to 'dlist' My code:...
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...
For a C program hangman game: Create the function int setup_game [int setup_game ( Game *g,...
For a C program hangman game: Create the function int setup_game [int setup_game ( Game *g, char wordlist[][MAX_WORD_LENGTH], int numwords)] for a C program hangman game. (The existing code for other functions and the program is below, along with what the function needs to do) What int setup_game needs to do setup_game() does exactly what the name suggests. It sets up a new game of hangman. This means that it picks a random word from the supplied wordlist array and...
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...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT