1ARC4 2==== 3 4.. warning:: 5 Use :doc:`salsa20` or :doc:`aes` (CTR mode) instead. This module is provided only for legacy purposes. 6 7ARC4_ (Alleged RC4) is an implementation of RC4 (Rivest's Cipher version 4), 8a symmetric stream cipher designed by Ron Rivest in 1987. 9 10The cipher started as a proprietary design, that was reverse engineered and 11anonymously posted on Usenet in 1994. The company that owns RC4 (RSA Data 12Inc.) never confirmed the correctness of the leaked algorithm. 13 14Unlike RC2, the company has never published the full specification of RC4, 15of whom it still holds the trademark. 16 17ARC4 keys can vary in length from 40 to 2048 bits. 18 19One problem of ARC4 is that it does not take a nonce or an IV. 20If it is required to encrypt multiple messages with the same long-term key, a 21distinct independent nonce must be created for each message, and a short-term 22key must be derived from the combination of the long-term key and the nonce. 23Due to the weak key scheduling algorithm of RC2, the combination must be 24carried out with a complex function (e.g. a cryptographic hash) and not by 25simply concatenating key and nonce. 26 27As an example, encryption can be done as follows:: 28 29 >>> from Crypto.Cipher import ARC4 30 >>> from Crypto.Hash import SHA 31 >>> from Crypto.Random import get_random_bytes 32 >>> 33 >>> key = b'Very long and confidential key' 34 >>> nonce = get_random_bytes(16) 35 >>> tempkey = SHA.new(key+nonce).digest() 36 >>> cipher = ARC4.new(tempkey) 37 >>> msg = nonce + cipher.encrypt(b'Open the pod bay doors, HAL') 38 39.. _ARC4: http://en.wikipedia.org/wiki/RC4 40 41.. automodule:: Crypto.Cipher.ARC4 42 :members: 43