SlideShare a Scribd company logo
1 of 15
RC4 Algorithm
RC4 Basics
• A symmetric key encryption algorithm invented by
Ron Rivest
– A proprietary cipher owned by RSA, kept secret
– Code released at the sites of Cyberpunk remailers
• Variable key size, byte-oriented stream cipher
consisting of 1 to 256 bytes (ie 8-bits to 2048-bits)
– Normally uses 64 bit and 128 bit key sizes.
RC4 Block Diagram
Plain Text
Secret Key
RC4
+
Encrypted
Text
Keystream
Description
• Choose a key (K) of length between 1 to 256
bytes
• Set the values of state vector S equal to values
of 0 to 255.
• ie. S[0]=0,s[1]=1…s[255]=255
• Create a Temporary array T.
• Copy the contents of K into T if length of K is
256 bytes or fill the remaining position with
the values of K again.
Steps:
• After this the array T is used to produce initial
permutation of S.
• A loop is executed from 0 to 255.
• S[i] and S[j] are swapped as per the arrangement
decided by T[i].
for i=0 to 255
S[i] = i
T[i] = K[i mod keylen]
Initial Permutation
j=0;
for i=0 to 255
j=(j+S[i]+T[i]) mod 256;
swap (S[i], S[j]);
Stream Generation
• Now S array is ready through initialization and
permutation.
• Then the initial key K is discarded.
• Now the key stream is going to be generated.
i=0;
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]
Contd…
• After this for encryption, k is XORed with the
next byte of the plain text.
• For decryption, k is XORed with the next byte
of cipher text.
Example
• Lets consider the stream cipher RC4, but
instead of the full 256 bytes, we will use 8 x 3-
bits.
• That is, the state vector S is 8 x 3-bits.
• We will operate on 3-bits of plaintext at a time
since S can take the values 0 to 7, which can
be represented as 3 bits.
• Assume we use a 4 x 3-bit key of K = [1 2 3 6].
And a plaintext P = [1 2 2 2]
• The first step is to generate the stream.
• Initialize the state vector S and temporary vector T. S is initialised so the
S[i] = i, and T is initialized so it is the key K (repeated as necessary).
• S = [0 1 2 3 4 5 6 7]
• T = [1 2 3 6 1 2 3 6]
• Now perform the initial permutation on S.
– j = 0;
– for i = 0 to 7 do
– j = (j + S[i] + T[i]) mod 8
– Swap(S[i],S[j]);
– end
• For i = 0:
– j = (0 + 0 + 1) mod 8 = 1
– Swap(S[0],S[1]);
– S = [1 0 2 3 4 5 6 7]
• For i = 1:
– j = 3
– Swap(S[1],S[3])
– S = [1 3 2 0 4 5 6 7];
• For i = 2:
– j = 0
– Swap(S[2],S[0]);
– S = [2 3 1 0 4 5 6 7];
• For i = 3:
– j = 6;
– Swap(S[3],S[6])
– S = [2 3 1 6 4 5 0 7];
• For i = 4:
– j = 3
– Swap(S[4],S[3])
– S = [2 3 1 4 6 5 0 7];
• For i = 5:
– j = 2
– Swap(S[5],S[2]);
– S = [2 3 5 4 6 1 0 7];
• For i = 6:
– j = 5;
– Swap(S[6],S[4])
– S = [2 3 5 4 0 1 6 7];
• For i = 7:
– j = 2;
– Swap(S[7],S[2])
– S = [2 3 7 4 0 1 6 5];
• Hence, our initial permutation of S = [2 3 7 4 0 1 6 5];
• Now we generate 3-bits at a time, k, that we XOR with each 3-bits of
plaintext to produce the cipher text. The 3-bits k is generated by:
• i, j = 0;
while (true) {
i = (i + 1) mod 8;
j = (j + S[i]) mod 8;
Swap (S[i], S[j]);
t = (S[i] + S[j]) mod 8;
k = S[t]; }
• The first iteration:
– S = [2 3 7 4 0 1 6 5]
– i = (0 + 1) mod 8 = 1
– j = (0 + S[1]) mod 8 = 3
– Swap(S[1],S[3])
– S = [2 4 7 3 0 1 6 5]
– t = (S[1] + S[3]) mod 8 = 7
– k = S[7] = 5
– Remember, P = [1 2 2 2]
• Remember, P = [1 2 2 2]
• So our first 3-bits of cipher text is obtained by: k XOR P
• 5 XOR 1 = 101 XOR 001 = 100 = 4
• The second iteration:
– S = [2 4 7 3 0 1 6 5]
– i = (1 + 1 ) mod 8 = 2
– j = (2 + S[2]) mod 8 = 1
– Swap(S[2],S[1])
– S = [2 7 4 3 0 1 6 5]
– t = (S[2] + S[1]) mod 8 = 3
– k = S[3] = 3
– Second 3-bits of cipher text are:
– 3 XOR 2 = 011 XOR 010 = 001 = 1
• After 4 iterations:
• To encrypt the plaintext stream P = [1 2 2 2]
with key K = [1 2 3 6] using our simplified RC4
stream cipher we get C = [4 1 2 0].
• (or in binary: P = 001010010010,
• K = 001010011110
• C = 100001010000)

More Related Content

Similar to Cryptography

Oct8 - 131 slid
Oct8 - 131 slidOct8 - 131 slid
Oct8 - 131 slid
Tak Lee
 
Matrix 2 d
Matrix 2 dMatrix 2 d
Matrix 2 d
xyz120
 
Lca seminar modified
Lca seminar modifiedLca seminar modified
Lca seminar modified
Inbok Lee
 

Similar to Cryptography (20)

Rc4 Research 2013
Rc4 Research 2013Rc4 Research 2013
Rc4 Research 2013
 
Cryptographic algorithms
Cryptographic algorithmsCryptographic algorithms
Cryptographic algorithms
 
Cryptographic algorithms
Cryptographic algorithmsCryptographic algorithms
Cryptographic algorithms
 
WiFi Security Explained
WiFi Security ExplainedWiFi Security Explained
WiFi Security Explained
 
AES.pptx
AES.pptxAES.pptx
AES.pptx
 
Constraint Satisfaction Problem (CSP) : Cryptarithmetic, Graph Coloring, 4- Q...
Constraint Satisfaction Problem (CSP) : Cryptarithmetic, Graph Coloring, 4- Q...Constraint Satisfaction Problem (CSP) : Cryptarithmetic, Graph Coloring, 4- Q...
Constraint Satisfaction Problem (CSP) : Cryptarithmetic, Graph Coloring, 4- Q...
 
Block Encryption Algorithm Project.docx
Block Encryption Algorithm Project.docxBlock Encryption Algorithm Project.docx
Block Encryption Algorithm Project.docx
 
The Understanding of GOST Cryptography Technique
The Understanding of GOST Cryptography TechniqueThe Understanding of GOST Cryptography Technique
The Understanding of GOST Cryptography Technique
 
AES (2).ppt
AES (2).pptAES (2).ppt
AES (2).ppt
 
Class-10-Mathematics-Chapter-1-CBSE-NCERT.ppsx
Class-10-Mathematics-Chapter-1-CBSE-NCERT.ppsxClass-10-Mathematics-Chapter-1-CBSE-NCERT.ppsx
Class-10-Mathematics-Chapter-1-CBSE-NCERT.ppsx
 
Oct8 - 131 slid
Oct8 - 131 slidOct8 - 131 slid
Oct8 - 131 slid
 
Cryptography Symmetric Key Algorithm (CSE)
Cryptography Symmetric Key Algorithm (CSE)Cryptography Symmetric Key Algorithm (CSE)
Cryptography Symmetric Key Algorithm (CSE)
 
Matrix 2 d
Matrix 2 dMatrix 2 d
Matrix 2 d
 
2d transformations
2d transformations2d transformations
2d transformations
 
2d transformations
2d transformations2d transformations
2d transformations
 
Lca seminar modified
Lca seminar modifiedLca seminar modified
Lca seminar modified
 
time_complexity_list_02_04_2024_22_pages.pdf
time_complexity_list_02_04_2024_22_pages.pdftime_complexity_list_02_04_2024_22_pages.pdf
time_complexity_list_02_04_2024_22_pages.pdf
 
Matrix 2 d
Matrix 2 dMatrix 2 d
Matrix 2 d
 
Number system
Number systemNumber system
Number system
 
3XRC4
3XRC43XRC4
3XRC4
 

More from SubashiniRathinavel (11)

PYTHON - OBJECT ORIENTED PROGRAMMING .pptx
PYTHON - OBJECT ORIENTED PROGRAMMING .pptxPYTHON - OBJECT ORIENTED PROGRAMMING .pptx
PYTHON - OBJECT ORIENTED PROGRAMMING .pptx
 
Basic Introduction to Python Programming
Basic Introduction to Python ProgrammingBasic Introduction to Python Programming
Basic Introduction to Python Programming
 
VB.NET Datatypes.pptx
VB.NET Datatypes.pptxVB.NET Datatypes.pptx
VB.NET Datatypes.pptx
 
Presentation1.pptx
Presentation1.pptxPresentation1.pptx
Presentation1.pptx
 
Quiz
QuizQuiz
Quiz
 
DSS
DSSDSS
DSS
 
Wireless lan security(10.8)
Wireless lan security(10.8)Wireless lan security(10.8)
Wireless lan security(10.8)
 
Wireless LAN
Wireless LANWireless LAN
Wireless LAN
 
SHA
SHASHA
SHA
 
Android workshop
Android workshopAndroid workshop
Android workshop
 
Online
OnlineOnline
Online
 

Recently uploaded

Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
PECB
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
SanaAli374401
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 

Recently uploaded (20)

Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 

Cryptography

  • 2. RC4 Basics • A symmetric key encryption algorithm invented by Ron Rivest – A proprietary cipher owned by RSA, kept secret – Code released at the sites of Cyberpunk remailers • Variable key size, byte-oriented stream cipher consisting of 1 to 256 bytes (ie 8-bits to 2048-bits) – Normally uses 64 bit and 128 bit key sizes.
  • 3. RC4 Block Diagram Plain Text Secret Key RC4 + Encrypted Text Keystream
  • 4. Description • Choose a key (K) of length between 1 to 256 bytes • Set the values of state vector S equal to values of 0 to 255. • ie. S[0]=0,s[1]=1…s[255]=255 • Create a Temporary array T. • Copy the contents of K into T if length of K is 256 bytes or fill the remaining position with the values of K again.
  • 5. Steps: • After this the array T is used to produce initial permutation of S. • A loop is executed from 0 to 255. • S[i] and S[j] are swapped as per the arrangement decided by T[i]. for i=0 to 255 S[i] = i T[i] = K[i mod keylen]
  • 6. Initial Permutation j=0; for i=0 to 255 j=(j+S[i]+T[i]) mod 256; swap (S[i], S[j]);
  • 7. Stream Generation • Now S array is ready through initialization and permutation. • Then the initial key K is discarded. • Now the key stream is going to be generated. i=0; 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]
  • 8. Contd… • After this for encryption, k is XORed with the next byte of the plain text. • For decryption, k is XORed with the next byte of cipher text.
  • 9. Example • Lets consider the stream cipher RC4, but instead of the full 256 bytes, we will use 8 x 3- bits. • That is, the state vector S is 8 x 3-bits. • We will operate on 3-bits of plaintext at a time since S can take the values 0 to 7, which can be represented as 3 bits. • Assume we use a 4 x 3-bit key of K = [1 2 3 6]. And a plaintext P = [1 2 2 2]
  • 10. • The first step is to generate the stream. • Initialize the state vector S and temporary vector T. S is initialised so the S[i] = i, and T is initialized so it is the key K (repeated as necessary). • S = [0 1 2 3 4 5 6 7] • T = [1 2 3 6 1 2 3 6] • Now perform the initial permutation on S. – j = 0; – for i = 0 to 7 do – j = (j + S[i] + T[i]) mod 8 – Swap(S[i],S[j]); – end • For i = 0: – j = (0 + 0 + 1) mod 8 = 1 – Swap(S[0],S[1]); – S = [1 0 2 3 4 5 6 7]
  • 11. • For i = 1: – j = 3 – Swap(S[1],S[3]) – S = [1 3 2 0 4 5 6 7]; • For i = 2: – j = 0 – Swap(S[2],S[0]); – S = [2 3 1 0 4 5 6 7]; • For i = 3: – j = 6; – Swap(S[3],S[6]) – S = [2 3 1 6 4 5 0 7];
  • 12. • For i = 4: – j = 3 – Swap(S[4],S[3]) – S = [2 3 1 4 6 5 0 7]; • For i = 5: – j = 2 – Swap(S[5],S[2]); – S = [2 3 5 4 6 1 0 7]; • For i = 6: – j = 5; – Swap(S[6],S[4]) – S = [2 3 5 4 0 1 6 7]; • For i = 7: – j = 2; – Swap(S[7],S[2]) – S = [2 3 7 4 0 1 6 5]; • Hence, our initial permutation of S = [2 3 7 4 0 1 6 5];
  • 13. • Now we generate 3-bits at a time, k, that we XOR with each 3-bits of plaintext to produce the cipher text. The 3-bits k is generated by: • i, j = 0; while (true) { i = (i + 1) mod 8; j = (j + S[i]) mod 8; Swap (S[i], S[j]); t = (S[i] + S[j]) mod 8; k = S[t]; } • The first iteration: – S = [2 3 7 4 0 1 6 5] – i = (0 + 1) mod 8 = 1 – j = (0 + S[1]) mod 8 = 3 – Swap(S[1],S[3]) – S = [2 4 7 3 0 1 6 5] – t = (S[1] + S[3]) mod 8 = 7 – k = S[7] = 5 – Remember, P = [1 2 2 2]
  • 14. • Remember, P = [1 2 2 2] • So our first 3-bits of cipher text is obtained by: k XOR P • 5 XOR 1 = 101 XOR 001 = 100 = 4 • The second iteration: – S = [2 4 7 3 0 1 6 5] – i = (1 + 1 ) mod 8 = 2 – j = (2 + S[2]) mod 8 = 1 – Swap(S[2],S[1]) – S = [2 7 4 3 0 1 6 5] – t = (S[2] + S[1]) mod 8 = 3 – k = S[3] = 3 – Second 3-bits of cipher text are: – 3 XOR 2 = 011 XOR 010 = 001 = 1
  • 15. • After 4 iterations: • To encrypt the plaintext stream P = [1 2 2 2] with key K = [1 2 3 6] using our simplified RC4 stream cipher we get C = [4 1 2 0]. • (or in binary: P = 001010010010, • K = 001010011110 • C = 100001010000)