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:
- KSA (key-scheduling algorithm) : initializes a permutation in the state vector S.
- 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.
Small modification to the well known RC4 algorithm that skips first n bytes of keystream, where
from rc4 import rc4
ciphertext = rc4.encrypt("key", "plaintext")