Skip to content

Python implementation of the stream cipher RC4 and RC4-drop[n].

License

Notifications You must be signed in to change notification settings

AleksaMCode/RC4

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RC4 Algorithm

Implementation of a simple stream cipher called RC4 (Rivest Cipher 4) and its variant RC4-drop[n]. While it is simple to use and to implement, multiple vulnerabilities have rendered it insecure.

RC4 is comprised of two phases:

  1. KSA (key-scheduling algorithm) : initializes a permutation in the state vector S.
  2. PRGA (pseudo-random generation algorithm): produces a stream of keys $K[0], K[1], ...$ which is XOR-ed with a given plaintext to obtain a ciphertext.

You can find detailed explanation about the algorithm online. Also, here is my favorite quote I read about RC4:

You can fit the code for RC4 onto a cocktail napkin, with plenty of room left over for the cocktail.

RC4-drop[n]

Small modification to the well known RC4 algorithm that skips first n bytes of keystream, where $n=0$ corresponds to regular RC4. The number of skipped bytes should be in range $n \in [256,3\,072]$ where $n \equiv 0 \pmod{256}$.

Usage

from rc4 import rc4

ciphertext = rc4.encrypt("key", "plaintext")