Skip to content
uencoder

RC4

RC4 is a stream cipher designed by Ron Rivest in 1987 — simple and fast, but with serious biases; it has been banned from TLS and other protocols.

Purpose

It provided padding-free, high-speed stream encryption and was once widely used in SSL/TLS and WEP, but was retired due to security flaws.

Mechanism

The KSA (key scheduling algorithm) permutes a 256-byte S-box with the key; the PRGA (pseudo-random generation algorithm) swaps two S-box entries per byte and emits one keystream byte, XORed with the plaintext. The first several keystream bytes show statistical biases.

Use cases

  • Legacy WEP/WPA Wi-Fi encryption
  • Old SSL/TLS (now disabled)
  • Historical Office/PDF encryption
  • Teaching example (stream-cipher flaws)

Examples

  • Input
    key="Secret", data="Hi"
    Output
    ciphertext byte stream

    Insecure; do not use in new systems

Common errors

Using RC4 in new systems
Use AES-GCM or ChaCha20-Poly1305

Related terms

Related tools

References