K010 / Symmetric ciphers (block and stream)
RC4
RC4 is a stream cipher that generates a pseudorandom keystream.
CRYPTOGRAPHY LAB / K010
Cryptography Lab · RC4
Run real computations and inspect intermediate states step by step.
Educational only. Never enter real passwords or secret keys. Computation stays in your browser; input and trace values are not sent to a server. Do not use this implementation in production.
RC4 (legacy)
See the scope above for fixed examples, reduced parameters and supported variants. Standard operation names and formulas are retained.Output
Previous state
- Definition and overview
- RC4 is a stream cipher that generates a pseudorandom keystream. Source document ↗
- Classification and reversibility
- A symmetric stream cipher; XOR makes decryption a reversible repetition of the same operation. Source document ↗
- Key or secret requirements
- Requires a secret key, typically 128 or 256 bits; the nonce is not secret but must be unique per key. Source document ↗
- Operating principle and structure
- KSA initializes the state with the key and PRG generates the keystream. Source document ↗
- Key size, block size and parameters
- Key length is 8–2048 bits, with a 128-bit default. Source document ↗
- Security strength and recommendation
- Cryptographically broken, unsuitable for further use and no longer recommended. Source document ↗
- Known attacks and vulnerabilities
- The FMS attack exploits initial keystream biases to recover part of the key; WEP and related schemes were broken. Source document ↗
- Standards and certification
- RFC 7465 prohibits TLS clients and servers from negotiating RC4 cipher suites. Source document ↗
- Typical uses
- A prominent stream cipher used in IEEE 802.11 wireless LAN WEP/WPA security schemes. Source document ↗
- Implementations, libraries and tools
- Legacy interoperability implementations include the RustCrypto rc4 crate. Source document ↗
- Decryption or decoding
- Repeat RC4 with the same key to decrypt. Source document ↗
- Advantages
- Originally fast, at seven cycles per byte on a Pentium. Source document ↗
- Limitations and cautions
- Cryptographically weak, retired from modern protocols and unsuitable for new security designs. Source document ↗
- Distinguishing encryption, encoding and hashing
- RC4 is keyed stream encryption, not encoding such as Base64 or hashing. Source document ↗
Practical examples
Example
Input plaintext and a secret key to RC4 to obtain ciphertext XORed with the keystream. Repeat with the same key to decrypt. Actual keys and secrets are not shown.
Procedure
Encryption: prepare plaintext and key, generate RC4 keystream, output XOR. Decryption: repeat RC4 with same key and reverse by XOR. Encoding changes format; hashing is one-way; RC4 is keyed reversible encryption.
Scenario
Restrict use to reading or decrypting legacy protocols and old systems. Remove RC4 from new systems and migrate to authenticated encryption. Do not expose keys in code, logs or examples.
Pitfalls and alternatives
RC4 is broken and banned or retired in TLS/SSH; avoid new use. Except for legacy integration use authenticated ciphers such as AES-GCM or ChaCha20-Poly1305. Avoid weak reuse or key management such as early WEP/WPA schemes.