Homework1-Sol - 1. a) Step 1: Convert key to K Key[0] = `G'...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
1. a) Step 1: Convert key to K Key[0] = ‘G’ = 0x47 = 01000111 => K[0] = 0100, K[1] = 0111; Keep doing we get all the K[i]; K is: 0100, 0111, 0100, 1111, 0100, 1011, 0100, 1110, 0100, 1001, 0100, 0111, 0100, 1000, 0101, 0100, Step 2: Initialize T, S S is simply from 0 to 15 S is: 0000, 0001, 0010, 0011, 0100, 0101, 0110, 0111, 1000, 1001, 1010, 1011, 1100, 1101, 1110, 1111, Since K is also 16-unit long, T is just a copy of K T is: 0100, 0111, 0100, 1111, 0100, 1011, 0100, 1110, 0100, 1001, 0100, 0111, 0100, 1000, 0101, 0100, Step 3: Initial permutation of S Follow this loop: //initial permutation of S j = 0; for (i=0; i< 16; i++) { j = (j + S[i] + T[i]) % 16; swap (S[i], s[j]); } Iteration 1: j = 0, i = 0, S[i] = 0, T[i] = 4 => j = 4, swap(S[0], S[4]) Keep doing we get: S after swap 0 4: 4, 1, 2, 3, 0, 5, 6, 7, 8, 9, a, b, c, d, e, f, S after swap 1 12: 4, c, 2, 3, 0, 5, 6, 7, 8, 9, a, b, 1, d, e, f, S after swap 2 2: 4, c, 2, 3, 0, 5, 6, 7, 8, 9, a, b, 1, d, e, f, S after swap 3 4: 4, c, 2, 0, 3, 5, 6, 7, 8, 9, a, b, 1, d, e, f, S after swap 4 11: 4, c, 2, 0, b, 5, 6, 7, 8, 9, a, 3, 1, d, e, f, S after swap 5 11: 4, c, 2, 0, b, 3, 6, 7, 8, 9, a, 5, 1, d, e, f, S after swap 6 5: 4, c, 2, 0, b, 6, 3, 7, 8, 9, a, 5, 1, d, e, f, S after swap 7 10: 4, c, 2, 0, b, 6, 3, a, 8, 9, 7, 5, 1, d, e, f, S after swap 8 6: 4, c, 2, 0, b, 6, 8, a, 3, 9, 7, 5, 1, d, e, f, S after swap 9 8: 4, c, 2, 0, b, 6, 8, a, 9, 3, 7, 5, 1, d, e, f, S after swap 10 3: 4, c, 2, 7, b, 6, 8, a, 9, 3, 0, 5, 1, d, e, f, S after swap 11 15: 4, c, 2, 7, b, 6, 8, a, 9, 3, 0, f, 1, d, e, 5, S after swap 12 4: 4, c, 2, 7, 1, 6, 8, a, 9, 3, 0, f, b, d, e, 5, S after swap 13 9: 4, c, 2, 7, 1, 6, 8, a, 9, d, 0, f, b, 3, e, 5, S after swap 14 12: 4, c, 2, 7, 1, 6, 8, a, 9, d, 0, f, e, 3, b, 5, S after swap 15 5: 4, c, 2, 7, 1, 5, 8, a, 9, d, 0, f, e, 3, b, 6, Step 4: Convert plaintext to bit array, same as the convert of key to K: P is: 0100, 0110, 0100, 1001, 0101, 0010, 0101, 0011, 0101, 0100, 0100, 0101, 0101, 1000, 0100, 0001, 0100, 1101, Step 5: Stream Generation
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Follow this loop: //Stream Generation i = 0; j = 0; l = 0; for (l=0; l< P. length ; l++) { //get key i = (i + 1) % 16; j = (j + S[i]) % 16; swap (S[i], [j]); t = (S[i] + S[j]) % 16; k = S[t]; //XOR key with plaintext to get ciphertext C[l] = P[l] ^ k; } Iteration 1: i = 0, j = 0, l =0 => i = (0 + 1) % 16 = 1; => j = (0 + 12) %16 = 12; => swap (S[1], S[12]) => t = (S[1] + S[12]) %16 = (12 + 14) % 16 = 10 => k = S[10] = 0; => C[0] = P[0] XOR 0 = 0100 = 0x4 Keep doing we get: i = (i+1) = 1 j = (j+S[i]) = 12 S after swap 1 12: 4, e, 2, 7, 1, 5, 8, a, 9, d, 0, f, c, 3, b, 6, t = (S[i]+S[j]) = 10 k = S[t] = 0 C[0] = 4 i = (i+1) = 2 j = (j+S[i]) = 14 S after swap 2 14: 4, e, b, 7, 1, 5, 8, a, 9, d, 0, f, c, 3, 2, 6, t = (S[i]+S[j]) = 13 k = S[t] = 3 C[1] = 5 i = (i+1) = 3 j = (j+S[i]) = 5 S after swap 3 5: 4, e, b, 5, 1, 7, 8, a, 9, d, 0, f, c, 3, 2, 6, t = (S[i]+S[j]) = 12 k = S[t] = 12 C[2] = 8 i = (i+1) = 4 j = (j+S[i]) = 6 S after swap 4 6: 4, e, b, 5, 8, 7, 1, a, 9, d, 0, f, c, 3, 2, 6, t = (S[i]+S[j]) = 9 k = S[t] = 13 C[3] = 4
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 9

Homework1-Sol - 1. a) Step 1: Convert key to K Key[0] = `G'...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online