Skip to content

Commit dcae768

Browse files
committed
docs: add description of RC4 operation and security warning
1 parent b10fa3f commit dcae768

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

ciphers/rc4.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,39 @@
1+
"""
2+
RC4 (Rivest Cipher 4) Stream Cipher Algorithm
3+
=============================================
4+
5+
RC4 is a symmetric stream cipher designed by Ron Rivest in 1987 for RSA Security.
6+
It is famous for its simplicity and speed in software. It operates on bytes,
7+
encrypting and decrypting data one byte at a time by XORing the plaintext with
8+
a pseudorandom keystream.
9+
10+
How it works:
11+
-------------
12+
1. Key Scheduling Algorithm (KSA):
13+
Initializes and permutes a 256-byte state array (the S-box) based on the secret key.
14+
2. Pseudo-Random Generation Algorithm (PRGA):
15+
Generates a continuous sequence of pseudorandom bytes (the keystream)
16+
from the S-box.
17+
With each byte generated, the state array is mutated to ensure unpredictability.
18+
3. Encryption/Decryption:
19+
The plaintext is XORed byte-by-byte with the keystream to produce the ciphertext.
20+
Since XOR is its own inverse, decryption uses the exact same process (XORing
21+
the ciphertext with the same keystream).
22+
23+
Security Status:
24+
----------------
25+
WARNING: RC4 is cryptographically broken and insecure.
26+
It suffers from significant keystream biases, particularly in the initial bytes.
27+
If the same key is reused, or if an attacker captures enough ciphertext, they
28+
can reconstruct the plaintext or the key. The use of RC4 is prohibited in modern
29+
protocols (such as TLS via RFC 7465). It is implemented here strictly for
30+
educational purposes.
31+
32+
Further reading:
33+
----------------
34+
* https://en.wikipedia.org/wiki/RC4
35+
"""
36+
137
from collections.abc import Generator
238

339

0 commit comments

Comments
 (0)