subject

Implement the RC4 stream cipher. 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.

Test your program with the following plain text file:

In cryptography, RC4 (Rivest Cipher 4 also known as ARC4 or ARCFOUR meaning Alleged RC4) is a stream cipher. While remarkable for its simplicity and speed in software, multiple vulnerabilities have been discovered in RC4, rendering it insecure. It is especially vulnerable when the beginning of the output keystream is not discarded, or when nonrandom or related keys are used. Particularly problematic uses of RC4 have led to very insecure protocols such as WEP

Using the following code below. Write TWO separate programs: encryption and decryption. The encryption program should input the plaintext file and output a cipher text in hex. The decryption program should input the cipher text file in hex and output the plaintext.

#include
#include
#include
#include

typedef uint8_t byte;
typedef struct
{
byte i, j;
byte S[256];
} Rc4State;

void swap(byte *a, byte *b)
{
byte temp = *a;
*a = *b;
*b = temp;
}

/*Initialization & initial permutation
also initialize i&j counters in state for stream generation*/
void initState(const byte K[256], int keylen, Rc4State *state)
{
byte T[256];
assert(keylen >= 1 && keylen <= 256);
int i;
for (i = 0; i < 256; i++) {
state->S[i] = i;
T[i] = K[i % keylen];
}

//Initial permutation of S
byte *S = state->S;
int j = 0;
for (i = 0; i < 256; i++) {
j = (j + S[i] + T[i]) % 256;
swap(&S[i], &S[j]);
}

//Initialize counters in state
state->i = state->j = 0;
}

/*Encrypt/Decrypt text by XORing with next byte of keystream*/
byte crypt(byte text, Rc4State *state)
{
byte t, k;
byte *i = &(state->i), *j = &(state->j);
byte *S = state->S;
*i = (*i + 1) % 256;
*j = (*j + S[*i]) % 256;
swap(&S[*i], &S[*j]);
t = (S[*i] + S[*j]) % 256;
k = S[t];

return text ^ k;
}

static byte rc4CryptByte(Rc4State *state, byte plainText)
{
byte *S = state->S;
byte i = ++(state->i);
byte j = (state->j += S[i]);

swap(&S[i], &S[j]);
byte t = S[i] + S[j];
byte k = S[t];

return plainText ^ k;
}

void rc4Crypt(Rc4State *state, byte text[], size_t len)
{
for (size_t i = 0; i < len; i++)
{
text[i] = rc4CryptByte(state, text[i]);
}

system("pause");
}

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 23.06.2019 03:30
In vista and windows 7, the appearance and personalization option allows you to change the
Answers: 1
question
Computers and Technology, 23.06.2019 04:20
4. a1. vince owns a television repair shop that is insured undera commercial package policy. the policy includes thebuilding and personal property coverage form and thecauses-of-loss broad form. the declarations page indicatesthat coverage applies to both the building and the namedinsured's business property. explain whether or not thefollowing losses would be covered under his policy.a. a fire occurs on the premises, and the building isbadly damaged.b. a burglar steals some money and securities from anunlocked safe.c. a business computer is damaged by vandals whobreak into the shop after business hours.d. a tornado touches down near the store. several tel-evision sets of customers in the shop for repair aredamaged in the storm.til
Answers: 2
question
Computers and Technology, 24.06.2019 16:00
This isn't about school but every time it tells me to watch an ad to unlock the answer to a question it prompts a survey and it just keeps loading. so i haven't been able to get answers for my tests in like a week.
Answers: 2
question
Computers and Technology, 24.06.2019 22:10
Function name: poly parameters: int returns: int description: a polynomial of degree n with coefficients a0,a1,a2,a3, . . ,an is the function p(x) = a0+a1x+a2x2+a3 ∗ x3+ . . +an ∗ xn this function can be evaluated at different values of x. for example, if: p(x) = 1+2x+ x2, then p(2) = 1+2 ∗ 2+22 = 9. if p(x) = 1+x2+x4, then p(2) = 21 and p(3) = 91. write a function poly() that takes as input a list of coefficients a0, a1, a2, a3, . . , an of a polynomial p(x) and a value x. the function will return poly(x), which is the value of the polynomial when evaluated at x.
Answers: 3
You know the right answer?
Implement the RC4 stream cipher. User should be able to enter any key that is 5 bytes to 32 bytes lo...
Questions
question
Mathematics, 31.10.2019 02:31
question
Mathematics, 31.10.2019 02:31
Questions on the website: 13722359