Lecture-3-RC4-A
Lecture-3-RC4-A
Random
key stream
generator
Plaintext k Ciphertext
byte stream byte stream
P C
Encryption
Random
key stream
generator
Ciphertext k Plaintext
byte stream byte stream
C P
Decryption
Random
key stream
generator
P = 11001100 C = 10100000
Encryption
-----
----- 10111101…
----- = 10111101…
10001111…
= 00110010… 00110010… =
RC4
A stream cipher
Designed in 1987 by Ron Rivest
Variable key size
Byte-oriented stream cipher
Widely used in web and wireless
8 to 16 operations are required per output byte
RC4
A variable-length key of from 1 to 256 bytes is
used to initialise a 256-byte state array S, with
elements S[0], S[1], ……, S[255].
RC4 → ( 3 Steps )
Step
1 Initialisation of S
The entries of S are set equal to the values from 0 to 255
in ascending order. i.e.
S[ 0 ] = 0
S[ 1 ] = 1
…… Concept
……
……
S[ 255 ] = 255
Stream ciphers
RC4
RC4
Given a key k of length m bytes
Step
2
Initial Permutation of S
// This involves starting with S[0] and going through S[255], and for each S[i],
swapping S[i] with another byte in S as obtained by some mechanism
RC4
Step
3 RC4 Encryption
Encryption continues shuffling array values
Sum of shuffled pair selects "stream key" value t
XOR with next byte of message to en/decrypt
i=j=0
for each message byte Mb
A i = ( i + 1 ) mod 256 Increment in i
S[ i ] = i
Initial permutation of S
j=0 m = 2 = Size of Key
for i = 0 to 3 do
j = ( j + S[ i ] + k[ i mod 2 ] ) mod 4
swap ( S[ i ], S[ j ] )
4 = Size of state array S
Stream ciphers
RC4 Example
Initial permutation of S
j=0 10001001 = 137 in Decimal
for i = 0 to 3 do
j = ( j + S[ i ] + k[ i mod 2] ) mod 4
k[0] 10001001 01010001 k[1]
swap ( S[ i ], S[ j ] )
S[0] S[1] S[2] S[3]
00000000 00000001 00000010 00000011
RC4 Example
Initial permutation of S
j=0 01010001 = 81 in Decimal
for i = 0 to 3 do
j = (j + S[i] + k[i mod 2]) mod 4
k[0] 10001001 01010001 k[1]
swap (S[i], S[j])
S[0] S[1] S[2] S[3]
00000001 00000000 00000010 00000011
RC4 Example
Initial permutation of S
j=0
for i = 0 to 3 do
j = (j + S[i] + k[i mod 2]) mod 4
k[0] 10001001 01010001 k[1]
swap (S[i], S[j])
S[0] S[1] S[2] S[3]
00000001 00000010 00000000 00000011
RC4 Example
Initial permutation of S
j=0
for i = 0 to 3 do
j = (j + S[i] + k[i mod 2]) mod 4
k[0] 10001001 01010001 k[1]
swap (S[i], S[j])
S[0] S[1] S[2] S[3]
00000001 00000010 00000011 00000000
RC4 Example
S[0] S[1] S[2] S[3]
00000000 00000001 00000010 00000011
Initial Permutation
of S