Ins RC4

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 15

Information and Network Security

Mr. Kashyap Sidapara, Student


Computer Science & Engineering
Assignment Question
RC 4 algorithm
Steps:

1. Key Scheduling
2. Key stream generation
3. Encryption & Decryption
1. Key Scheduling
Syntax:-
Initialization j=0
For i = 0 to size of array
j = [ j + s(i) + t(i) ] mod size of array
Swap [ s(i), s(j) ]
where, s(i)  state vector
t(i)  key vector
 No. is iteration = size of array
Note:- s-array & key array must be same. If key is sort then repeat it.
2. Key Stream Generation
Initialization i=0, j=0
i = ( i + 1)mod size of array
j = [ j + s(i) ] mod size of array
Swap [ s(i), s(j) ]

T = [ s(i) + s(j) ] mode size of array


K = s(t)

K = s[{ s(i) + s(j) } mode size of array]


3. Encryption & Decryption

Encryption  PT XoR New key


Decryption  CT XoR New key
Example
S-array:- [ 0 1 2 3 ]
Key array:- [ 1 2 3 6 ]
Plain text:- [ 1 2 2 2 ]

s(0) s(1) s(2) s(3)


S-array:- [0 1 2 3]

t(0) t(1) t(2) t(3)


Key array:- [ 1 2 3 6 ]
Step - 1
1. 2.
j = 0 (i = 0 to 3), i = 0 j = 1, i = 1
j = [ j + s(i) + t(i) ] mod size of array j = [ j + s(i) + t(i) ] mod size of array
j = [ 0 + 0 + 1 ] mod 4 j = [ 1 + 0 + 2 ] mod 4
j = 1 mod 4 j = 3 mod 4
j=1 j=3

i = 0, j = 1 i = 1, j = 3
Swap s(0), s(1) Swap s(1), s(3)

S=[1 0 2 3] S=[1 3 2 0]
Step - 1
3. 4.
j = 3, i = 2 j = 0, i = 3
j = [ j + s(i) + t(i) ] mod size of array j = [ j + s(i) + t(i) ] mod size of array
j = [ 3 + 2 + 3 ] mod 4 j = [ 0 + 0 + 6 ] mod 4
j = 8 mod 4 j = 6 mod 4
j=0 j=2

i = 2, j = 0 i = 3, j = 2
Swap s(0), s(2) Swap s(2), s(3)

S=[2 3 1 0] S=[2 3 0 1]
Step – 2 (key stream generation)
1.
Initialization i=0, j=0 Swap [ s(i), s(j) ]
i = ( i + 1)mod size of array Swap [ s(1), s(3) ]
i = ( 0 + 1)mod 4 S=[2 1 0 3]
i = 1 mod 4
i=1 T = [ s(i) + s(j) ] mode size of array
T = [ 1 + 3 ] mod 4
j = [ j + s(i) ] mod size of array T=0
j = [ 0 + 3 ]mod 4
j = 3 mod 4 K = s(t)
j=3 K = s(0)
K=2
Step - -22 Analysis (Passive Attack)
2) Traffic
Step
2.
i=1, j=3 Swap [ s(i), s(j) ]
i = ( i + 1)mod size of array Swap [ s(2), s(3) ]
i = ( 1 + 1)mod 4 S=[2 1 3 0]
i = 2 mod 4
i=2 T = [ s(i) + s(j) ] mode size of array
T = [ 3 + 0 ] mod 4
j = [ j + s(i) ] mod size of array T=3
j = [ 3 + 0 ]mod 4
j = 3 mod 4 K = s(t)
j=3 K = s(3)
K=0
Step - 2
3.
i=2, j=3 Swap [ s(i), s(j) ]
i = ( i + 1)mod size of array Swap [ s(3), s(3) ]
i = ( 2 + 1)mod 4 S=[2 1 3 0]
i = 3 mod 4
i=3 T = [ s(i) + s(j) ] mode size of array
T = [ 0 + 0 ] mod 4
j = [ j + s(i) ] mod size of array T=0
j = [ 3 + 0 ]mod 4
j = 3 mod 4 K = s(t)
j=3 K = s(3)
K=2
Step - 2
4.
i=3, j=3 Swap [ s(i), s(j) ]
i = ( i + 1)mod size of array Swap [ s(0), s(1) ]
i = ( 3 + 1)mod 4 S=[1 2 3 0]
i = 4 mod 4
i=0 T = [ s(i) + s(j) ] mode size of array
T = [ 1 + 2 ] mod 4
j = [ j + s(i) ] mod size of array T=3
j = [ 3 + 2 ]mod 4
j = 5 mod 4 K = s(t)
j=1 K = s(3)
K=0
Step - 3
Encryption & Decryption

PT = [ 1 2 2 2 ]  [ 0001 0010 0010 0010 ]


Key = [ 2 0 2 0 ]  [ 0010 0000 0010 0000 ]

Apply XoR Operation  [ 0011 0010 0000 0010 ]

Final answer is  [ 3 2 0 2 ]
www.paruluniversity.ac.in

You might also like