RC2, RC4, RC5 key length While reading the Wiki page on RC4 I noticed that the key size must be in the range of 40–2,048 bits. So should I understand like this, that I can have a key that has length of, lets say 333 bits? (any decimal number between 40-2048?) How about inputs length?

Imagine that I can ask a user to give me an input length (for example, 1027) and keylength (lets say, 359) and I can use them?

Same question about RC2 - the key size must be in the range of 8-128 [bits] and RC5 - the key size must be in the range 0 - 2040 [bits].

Can I use any key length which is in the given range? Even the exotic one, like, I dont know, 879 or 123 bits as the length of the key?
Yes, you can have a key of any length of that range (as long as it is an integral number of bytes), but really, why?  There is absolutely no reason to.


If the key is uniformly distributed, anything over 256 bits is total overkill and completely pointless.
If the key is not uniformly distributed (maybe it's a passphrase or something), you should not be using it directly as the RC4 key.  Instead, you should hash it first (preferably using a slow hash like PBKDF2) and use the result as the RC4 key; and the output of the hash will be something like 128 bits or 256 bits, so again, the range doesn't matter.


Bottom line: If you need to ask about the exact range of key lengths, you're probably using RC4 incorrectly.  Instead, stick to a key that is 128-256 bits long and is uniformly distributed and generated using a cryptographic-quality pseudorandom number generator or using a suitable hash/KDF function.



Update: apparently RC2 does allow arbitrary bit lengths for its keys, per a comment from Henno Brandsma (thanks!).  However, that doesn't change the bottom line.  I would not recommend using unusual length keys.  Stick to ordinary lengths, like 128 bits or 256 bits.