RC4 Cipher

Suggested experiment

  • Click GET QUOTE to put a long, english plaintext in the INPUT TEXT box.
  • Enter any characters as a key in the KEY box.
  • Click ENCRYPT to encrypt the plaintext using RC4.
  • Click the FREQUENCY tab to see if the keystream (red) is more uniform than standard english (black).
  • Click INITIALIZATION and then STEP repeatedly to see every step of the initialization part of the algorithm (the first 256 steps).
  • Click KEY STREAM and RUN to step through the actual encryption.

Overview

This applet demonstrates the RC4 stream cipher, which is used in many applications, including the SSL that protects secure web pages (HTTPS). The cipher is based on an S-array that contains the numbers from 0 to 255. Initially, these numbers are in numeric order. During the initialization, they are scrambled according to the key. During encryption, they are used to generate a pseudorandom stream, while continuing to become more scrambled. This stream is XORed with the plaintext to encrypt it.

Frequency

The FREQUENCY tab shows the frequency distribution of the keystream that is generated, compared to the frequency of characters in standard english. The stream should be approximately uniform, and should become more uniform as the plaintext becomes longer.

Initialization

The INITIALIZATION tab allows you to step through the first 256 steps of the algorithm with the STEP button, watching the S-array become scrambled. Click FINISH to run all the steps in order. This transposition of the array is dependent on the key.

Key Stream

The KEY STREAM tab allows you to step through the encryption process using the array set up by the FREQUENCY tab. Further transpositions are performed on the array, but they are not explicity dependent on the key. This step generates the key stream that is XORed with the plaintext to give ciphertext.