0% found this document useful (0 votes)
10 views

Lecture-3-RC4-A

Uploaded by

awaisqarni640
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)
10 views

Lecture-3-RC4-A

Uploaded by

awaisqarni640
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/ 18

Stream ciphers

 A stream cipher processes input elements continuously,


producing output one element at a time.

 Stream ciphers process messages a bit or byte or


character at a time when en/decrypting.
 Process the message bit by bit (as a stream)
 The most famous of these is the Vernam cipher
 Invented by Vernam, working for AT&T, in 1917
 Simply add bits of message to random key bits
 Unconditionally secure provided key is truly random

 Typically have a random stream key


 Combined (XOR) with plaintext bit by bit
 Ci = Mi XOR StreamKeyi
Stream ciphers

Continuous data streams, e.g., telephone samples of 8 bit length


– wasteful to fit into 64 bit block for encoding
– works only for symmetric cryptography
– used when no block structure (e.g. voice)

Stream Cipher Structure


Stream ciphers
Stream Cipher Structure
Key Encryption
K

Random
key stream
generator

Plaintext k Ciphertext
byte stream byte stream
P C

Encryption

A stream cipher Encryption


Stream ciphers
Stream Cipher Structure
Key Decryption
K

Random
key stream
generator

Ciphertext k Plaintext
byte stream byte stream
C P

Decryption

A stream cipher Decryption.


Stream ciphers
Stream Cipher Structure
Example
Key (K)

Random
key stream
generator

Paintext k = 01101100 Ciphertext


byte stream byte stream
P C

P = 11001100 C = 10100000
Encryption

A stream cipher Encryption Example


Stream ciphers
Stream Cipher Structure

Encrypt by bitwise XOR of


plaintext and key:
ciphertext = plaintext  key

-----
----- 10111101…
----- = 10111101…
 10001111… 
= 00110010… 00110010… =

Key is a random bit sequence


as long as the plaintext Decrypt by bitwise XOR of
ciphertext and key:
ciphertext  key =
(plaintext  key)  key =
plaintext  (key  key) =
A  B=C plaintext

Here,  = XOR Symbol


C  B=A
C  A=B
Stream ciphers

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

 Extremely simple and easy to explain, very fast


Stream ciphers

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].

 For encryption and decryption, a byte k is


generated from S by selecting one of the 255
entries in a systematic way.

 As each value of key is generated, the entries in


S are once again permuted
Stream ciphers

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

Step Initialisation of S Code


1
//********************************************************
S[ 0 ] = 0
S[ 1 ] = 1
for i = 0 to 255 do ……
S[ i ] = i ……
……
S[ 255 ] = 255
//********************************************************
Stream ciphers

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

m = Size of key > 0


j=0
256 = Size of state array S
for i = 0 to 255 do
j = ( j + S[ i ] + k[ i mod m ] ) mod 256
swap ( S[ i ], S[ j ] )
Result of mod 256 = 0 to 255
i mod m = 0 to m-1
Stream ciphers

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

B j = ( j + S[ i ] ) mod 256 Calculation of j

C swap( S[ i ] , S[ j ] ) Final Permutation of S

D t = ( S[ i ] + S[ j ] ) mod 256 Calculation of t

E Ci = Mb XOR S[ t ] XOR Operation


RC4 Example
Given a key k of length 2 bytes k[0] k[1]
10001001 01010001

S[0] S[1] S[2] S[3]


Initialisation of S 00000000 00000001 00000010 00000011
//*****************************
for i = 0 to 3 do Loop executes according to the size of state array S

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

i=0 j = (0 + S[0] + k[0]) mod 4


= (0 +0+137) mod 4= 1
swap ( S[0], S[1] )
S[0] S[1] S[2] S[3]
00000001 00000000 00000010 00000011
Stream ciphers

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

i=1 j = (1 + S[1] + k[1]) mod 4


= (1 + 0 + 81) mod 4= 2
swap (S[1], S[2])
S[0] S[1] S[2] S[3]
00000001 00000010 00000000 00000011
Stream ciphers

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

i=2 j = (2 + S[2] + k[0]) mod 4


= (2 +0+137)%4= 3
swap (S[2], S[3])
S[0] S[1] S[2] S[3]
00000001 00000010 00000011 00000000
Stream ciphers

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

i=3 j = (3 + S[3] + k[1]) mod 4


= (3 +0+81)%4= 0
swap (S[3], S[0])
S[0] S[1] S[2] S[3]
00000000 00000010 00000011 00000001
Stream ciphers

RC4 Example
S[0] S[1] S[2] S[3]
00000000 00000001 00000010 00000011

Initial Permutation
of S

S[0] S[1] S[2] S[3]


00000000 00000010 00000011 00000001

Note: Not complete, Encryption Step still remaining.

You might also like