How to generate the Keystream from IV+Key in RC4 So I understand that a keystream is generating from a key and is the length of the message you want to send, so that you can properly XOR every bit. But I'm having trouble finding and understanding the algorithm for creating the keystream from the IV and key. 

One idea I had is if you have a message of length 100 and key of length 10, then your IV is 90 bits to cover the rest of the message, and then the key string is just the concatination of IV + key.
The length of Key and length of IV bear no relationship with the length of the message.

RC4 is deprecated. The way it was supposed to be used is:


Generate a random IV, wide enough that it will remain unique (e.g. 32 bytes), and emit that as header of the ciphertext since the receiver will need it.
Concatenate Key (limited to 256 minus IV size in bytes) and IV
Initialize the cipher with that (there are 256 steps that cycle on the concatenated Key and IV).
Generate as much output a there is plaintext, and use it as keystream to XOR with plaintext, yielding ciphertext.


But various attacks exist. If for some reason one is locked with that cipher from the past (rather than e.g. ChaCha which is safer, faster, and less RAM-intensive), and nevertheless wants to be secure, it's advisable to at least discard some of the initial keystream (e.g. the first 1024 bytes) in an intermediary step before 4.

And of course if one is locked with a particular protocol, it must be done as in that protocol.



Note: if the key is derived from a passphrase memorized by a user, then it is highly advisable to use some form of stretching for the password-to-key conversion:


The best would be a modern and well parametrized password hash function such as Argon2 or Scrypt.
If not, we can use RC4 itself by using the amount of keystream skipped as the workfactor parameter (e.g. 222 bytes). Also, we need to limit the password length to be sure that there remains room for the IV.


Independently, the character set of the password must be well-defined (e.g. UTF-8).