Masm Program Using Visual Studios Can Someone Please Help Me With This It Is An Exam 2746377

MASM Program (using Visual Studios)

Can someone please help me with this? It is an example program to help us better understand the assembly language. However, I can not get mine to compile and I’m not sure what I am doing wrong. Thank you in advance.

The program should be implemented with a driver program that calls the RC4 key stream generation functions, encrypting “hello World” with a key of “test”.

RC4 is a stream cipher originally developed in 1987 by Ron Rivest of RSA Security [3]. Because of its simplicity and speed, it was used extensively for several applications and became the basis for the WEP standard used for wireless encryption. The basic concept is that a pseudo-random string of bytes is generated which is XOR’d with the plaintext to generate the cipher text.


Declare state array256 bytes.

Declare and initialize the key array key ={”test”}

Declare the output stream array 1024 bytes.

Declare plaintext character array ={“Hello World”} – be certain to include the null terminator.

Declare the cypherText array at least 12 characters long initialized to 0.

Declare the plaintextOut array at least 12 characters long initialized to 0.

Declare and Initialize len=11

Declare and Initialize keylen=4

Call rc4Init passing (state, key, keylen)

Call rc4KeyGen(state, stream, len);

for (int i = 0; i < len; i++)


                              cypherText[i] = stream[i] xor plainText[i];

                              plainTextOut[i] = stream[i] xor cypherText[i];

                              printf(“%02X %02X”, stream[i], cypherText[i]);

                              Skip to a new line


print plainText and plainTextOut


To generate the random bytes, a permutation of all possible combinations of bytes is stored in a 256 element array known as the S array. Initialization of the S array uses a key of arbitrary length to “shuffle” the locations using the simple algorithm shown:

// Key Scheduling Algorithm

// Input: state – the state used to generate the keystream

//        key – Key to use to initialize the state

//       keylen – length of key in bytes

void rc4Init(unsigned char state[], unsigned char key[], int keylen)


               int i, j = 0, t;

               for (i = 0; i < 256; ++i)

                              state[i] = i;

               for (i = 0; i < 256; ++i) {

                              j = (j + state[i] + key[i % keylen]) % 256;

                              t = state[i];

                              state[i] = state[j];

                              state[j] = t;



The result of this initialization is an array with values 0-255 in an arbitrary order based on the key. Once the S array has been initialized, an equally simple algorithm is used to generate as many pseudo-random bytes as necessary to encode the message.

// Pseudo-Random Generator Algorithm

// Input: state – the state used to generate the keystream

//        out – Must be of at least “len” length

//        len – number of bytes to generate

void rc4KeyGen(unsigned char state[], unsigned char out[], int len)


               int i = 0, j = 0, x, t;

               unsigned char key;

               for (x = 0; x < len; ++x) {

                              i = (i + 1) % 256;

                              j = (j + state[i]) % 256;

                              t = state[i];

                              state[i] = state[j];

                              state[j] = t;

                              out[x] = state[(state[i] + state[j]) % 256];



Compile and run program – test with the test case indicated above.

Example Output:

Welcome to pat programmer’s RC4 stream cypher













Plaintext : Hello World

Plaintext Out: Hello World

Prof. Angela


Calculate Price

Price (USD)
Open chat