- Joined
- May 30, 2011
- Messages
- 443
- Reaction score
- 95
The .NET Framework does not support RC4 natively, and very literally every implementation I've seen is nonfunctional. I've attempted to write an implementation of my own, but like the other libraries I've used, it fails to generate a keystream consistent with the IETF test vectors. My source is identical to the specification on the RC4 Wikipedia page so far as I can tell.
PHP:
var key = new byte[] { 1, 2, 3, 4, 5 };
var sbox = Enumerable.Range(0, 256).Select(i => (byte)i).ToArray();
for (int i = 0, j = 0; i < sbox.Length; i++) {
j = (j + key[i % key.Length] + sbox[i]) % 256;
sbox.Swap(i, j);
}

