using System.Security.Cryptography;
public static void Main()
var pwd = Encoding.UTF8.GetBytes("SomePwd");
for (var input = 1; input < 1000000; input += 1000)
var enc = Convert.ToBase64String(RC4.Encrypt(pwd, BitConverter.GetBytes(input)));
var dec = BitConverter.ToInt32(RC4.Decrypt(pwd, Convert.FromBase64String(enc)));
Console.WriteLine($"{input}: {enc} is equal to {dec}");
public static byte[] Encrypt(byte[] pwd, byte[] data)
cipher = new byte[data.Length];
for (i = 0; i < 256; i++)
key[i] = pwd[i % pwd.Length];
for (j = i = 0; i < 256; i++)
j = (j + box[i] + key[i]) % 256;
for (a = j = i = 0; i < data.Length; i++)
k = box[((box[a] + box[j]) % 256)];
cipher[i] = (byte)(data[i] ^ k);
public static byte[] Decrypt(byte[] pwd, byte[] data)
return Encrypt(pwd, data);