0% found this document useful (0 votes)
31 views8 pages

Project New Questions

The document provides instructions for two exam questions on encryption algorithms. Question 1 involves implementing the RC4 stream cipher in MATLAB to encrypt and decrypt a message. Question 2 asks students to perform the AES encryption process on a sample 4x4 block, including
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views8 pages

Project New Questions

The document provides instructions for two exam questions on encryption algorithms. Question 1 involves implementing the RC4 stream cipher in MATLAB to encrypt and decrypt a message. Question 2 asks students to perform the AES encryption process on a sample 4x4 block, including
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Name: Student Number:

Project # 1
Course: COE 465
Class Network Security One
week
EA
s

Dr. Mohammed Alsaedi Date:04/14/2021


EAA
AAA
EAE
AEA
Sem. Please answer all questions
The first exam has four main questions that deserve 20 marks of the course grades.
Please answer all questions correctly to get the full marks of the exam.

Mapping course learning outcomes with exam questions

CLO Exam Marks Mark/CLO Students Marks


Question
1.1, 1.2, 1.3, Q1 40 8
2.1, 3.2
1.1, 1.2, 1.3, Q2 60 10
2.1, 3.2, 4.3

Student signature:

Student Signature confirming that Feedback was received:


………………………………………………………………………………………………………………………......
Comments by student: .............................………………….…………………………………………………….............
...................……………………………………………………………………………............................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
Q1. RC4 Encryption Algorithm
RC4 is a stream cipher and variable length key algorithm. This algorithm encrypts one byte at a time (or
larger units on a time). A key input is pseudorandom bit generator that produces a stream 8-bit number
that is unpredictable without knowledge of input key, The output of the generator is called key-stream, is
combined one byte at a time with the plaintext stream cipher using X-OR operation. Refer to the figure
attached and the steps of encryption starts key generation, encryption, and decryption. The steps are
detailed as follows:

1. Key Generation
A. Initialization of S
To begin, the entries of S are set equal to the values from 0 through 255 in ascending order; that is, S[0]
0, S[1] 1, . . ., S[255] 255.A temporary vector,T,is also created.If the length of the key K is 256 bytes,then
K is transferred to T.Otherwise,for a key of length keylenbytes,the first keylenelements of T are copied
from K,and then K is repeated as many times as necessary to fill out T.These preliminary operations can
be summarized as:

for i =0 to 255 do
S[i]= i;
T[i] = K[i mod keylen];

B. Initial Permutation of S

Next we use T to produce the initial permutation of S.This involves starting with S[0] and going through
to S[255] and,for each S[i],swapping S[i] with another byte in S according to a scheme dictated by T[i]:

/* Initial Permutation of S */
J= 0;
for i =0 to 255 do ;
j= (j S[i] T[i]) mod 256;
Swap (S[i], S[j]);

C. STREAM GENERATION

Once the S vector is initialized, the input key is no longer used. Stream generation involves cycling
through all the elements of S[i] and, for each S[i],swapping S[i] with another byte in S according to a
scheme dictated by the current configuration of S. After S[255] is reached, the process continues, starting
over again at S[0]:
/* Stream Generation */
i, j= 0;
while (true)
i= (I + 1) mod 256;
j= (j + S[i]) mod 256;
Swap (S[i], S[j]);
t= (S[i] + S[j]) mod 256;
k= S[t];
D. Encryption & Decryption

To encrypt, XOR the value k with the next byte of plaintext. To decrypt, XOR the value k with the next
byte of Ciphertext. The attached figure illustrates the RC4 logic.

Procedures and Requirements:

Attached two files one under title KSA for stream generation and pseudorandom numbers generation
PRGA. Open a Matlab script under title name main_script. Copy the following commands in the script:

Clear;
Clc;
key = input('Please, enter the key\n','s');
plaintext = input('please, enter the message\n','s');

Use the following key:


*&^%$#@!)(87
Use also the following message:
The toga party was cancelled prior arrival of agent at 9:30 PM

Then perform the following:


1. Encryption starts with generating pseudorandom numbers and randomizing the key using the
plaintext. Use the following command
Z=uint8(PRGA(KSA(key), size(plaintext,2)));

2. Use the following command to prepare the text message to be XORed with the randomized
key.

P = uint8(char(plaintext));

3. XORed the message with pseudorandom numbers generated from the key and show the
encrypted message as characters and as hexadecimal also:
encmsg = bitxor(Z, P);
char(encmsg)
encmsg_hex = mat2str(dec2hex(encmsg,2));

4. Decrypt the encrypted message by XORing the encrypted message and the key then show the
decrypted message using the following command:

char(bitxor(Z, uint8(encmsg)))
Q2. AES Encryption Algorithm
The encryption process in AES includes add key, Bytesub, shiftrows, and mixcolumn.
However, we would like to abbreviate the important process with a small 4 x 4 block for
encryption and decryption given the Xored plaintext with the key block as below:
1E 2A 41 13
2B 4C 21 77
4F 5D 27 18
19 12 7B BD

A. Encryption

1. Perform subBytes using the table in Figure 2 and include your results in
the empty table given below.

2. Use the following instructions with the file question2 to transfer matrices
in the file from hexadecimal to decimal.

msg=matrix_transform_dec(msg);
subbyte=matrix_transform_dec(subbyte);
matrix=matrix_transform_dec(matrix);
matrix_invrs=matrix_transform_dec(matrix_invrs);

3. Use the Matlab file question2. Multiply the result in part a by the
following matrix then do XOR operations and put the results of
Cyphertext.
Example: 7B*3=7B*(2+1)=7*B*2+7B=XOR (01111011*2, 01111011)=
XOR(11110110, 01111011)= 10001101= 8D

4. Use the following command to perform part A.3. The result can be taken
from the variable enc_msg then fill out the empty box.

enc_msg1 = mod(mix_columns (subbyte, matrix),256);


enc_msg=compose("%X", enc_msg1);

02 03 01 01
01 02 03 01
02 03 01 01
03 01 01 02

B. Perform decryption process

1. Multiply the cyphertext in A2 by the following inverse matrix with


necessary XOR operations then put your results in the empty box (Use the
variable dec_msg).

0E 0B 0D 09
09 0E 0B 0D
0D 09 0E 0B
0B 0D 09 0E
2. Use the following command in question2 to perform part B.1. get the
result from dec_msg and fill out the empty box.

dec_msg= mod(mix_columns (enc_msg, matrix_invrs),256);


dec_msg=compose("%X", dec_msg);

3. Perform inverse subByte using the table in Figure 2 for the result in B2 then put your
results in the empty block

4. What do you notice about B3 and the plaintext? Are they similar or different?
Figure 1. RC4
Process (Q1)
Figure 2: Table 256 x 256 Hexadecimal for AES (Q2)

You might also like