mattdallas6214
10.04.2020 •
Computers and Technology
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");
}
Solved
Show answers
More tips
- O Other What is a Disk Emulsifier and How Does it Work?...
- F Family and Home What does a newborn need?...
- F Family and Home Choosing the Right Car Seat for Your Child: Tips and Recommendations...
- F Food and Cooking How to Get Reconfirmation of Registration?...
- C Computers and Internet How to Get Rid of Spam in ICQ?...
- A Art and Culture Who Said The Less We Love a Woman, the More She Likes Us ?...
- F Family and Home How to Get Rid of Your Neighbors?...
- S Society and Politics How Could Nobody Know About the Dead Mountaineers?...
- H Health and Medicine How to Cure Adenoids?...
- H Health and Medicine Why Wearing a Back Brace Can Be Beneficial During Back Strain?...
Answers on questions: Computers and Technology
- C Computers and Technology Поги СИСК Logoc) Put these storage devices in order of cost per Gb of storage from the smallest to thelargest1. Magnetic tapeOG Smallest...
- M Mathematics 23x67 estimate then find the prouduct...
- M Mathematics What is a positive minus a negative...
- C Chemistry When making calculations, you should rely on the precision of your measured data. true false...
- B Biology The term prehistory refers to the time before writing was invented.true or false?...
- M Mathematics 1) 10-2v = -5v-50 2) r+15=4r-6 write all !...
- P Physics What types of energy transformations take place in a windmill...
- C Chemistry What is the volume of a sample of liquid mercury that has a mass of 76.2 g, given that the density of mercury is 13.6 g/ml?...
- B Business Part of the lands end business model includes purchasing products and then selling them again without any reprocessing. lands end is operating in the...
- B Biology Add 4.503 m and 6.23 m, using significant digits. how many significant digits would the answer contain?...
Ответ:
A. Pinning
Explanation:
I just took the test.