Project New Questions
Project New Questions
Project # 1
Course: COE 465
Class Network Security One
week
EA
s
Student signature:
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.
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');
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.
02 03 01 01
01 02 03 01
02 03 01 01
03 01 01 02
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.
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)