Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Can you help me solve this problem It for witeshark Network security Computer sc

ID: 3872398 • Letter: C

Question

Can you help me solve this problem It for witeshark Network security Computer science elective I am doing it now as we speak untitled Implement the RC4 stream cipher in C++ or JAVA. 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 MUST NOT BE HARD CODED IN THE PROGRAM. Test your program with the following plain text: http://cms.uhd. edu/Faculty/yuans/courses/cs3326/projects/rc4Input.txt Your program must be able to do both encryption and decryption. Submit the following source code A screen shot showing, the encryption then decryption with a 5 byte key The ciphertext from the encryption, saved in hexdecimal Cyou may want to The plaintext from the decryption of the cipher text (you need to convert 1 use the "hex" output manipulator) hex text to number) I press the Thek: ht tr s cns.uhd.edu/Faculty link:http://cms.uhd.edu/Faculty/yuans/courses/cs3326/Projects/rc4Input.txt It display the below In cryptography, RÇ4 CRivest cipher 4 also known as ARC4 or ARCFOUR meaning Alleged while remarkable for its simplicity and speed in software, multiple vulnerabilities Mi4e isemarkab e for s simplicity and speed in software, multiple vulnerabilities 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.

Explanation / Answer

#include <stdio.h>
#include <stdint.h>
#include <assert.h>


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]);
    }
}