Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// <summary>
- /// RC4 encryption algorithm
- /// </summary>
- /// <param name="bytes">Input bytes</param>
- /// <param name="key">Key bytes</param>
- /// <returns>encrypted bytes</returns>
- public static byte[] Encrypt(byte[] bytes, byte[] key)
- {
- byte[] z = new byte[bytes.Length];
- byte[] s = new byte[256];
- byte[] k = new byte[256];
- byte temp;
- int i, j;
- for (i = 0; i < 256; i++)
- {
- s[i] = (byte)i;
- k[i] = key[i % key.GetLength(0)];
- }
- j = 0;
- for (i = 0; i < 256; i++)
- {
- j = (j + s[i] + k[i]) % 256;
- temp = s[i];
- s[i] = s[j];
- s[j] = temp;
- }
- i = j = 0;
- for (int x = 0; x < z.GetLength(0); x++)
- {
- i = (i + 1) % 256;
- j = (j + s[i]) % 256;
- temp = s[i];
- s[i] = s[j];
- s[j] = temp;
- int t = (s[i] + s[j]) % 256;
- z[x] = (byte)(bytes[x] ^ s[t]);
- }
- return z;
- }
- public static byte[] Encrypt(byte[] bytes, byte[] key)
- byte[] z = new byte[bytes.Length];
- byte[] s = new byte[256];
- byte[] k = new byte[256];
- byte temp;
- int i, j;
- for (i = 0; i < 256; i++)
- {
- ...
- k[i] = key[i % key.GetLength(0)];
- }
- ...
- for (i = 0; i < 256; i++)
- {
- j = (j + s[i] + k[i]) % 256;
- ...
- }
- j = (j + s[i] + k[i]) % 256;
- i = (i + 1) % 256;
- j = (j + s[i]) % 256;
- ...
- int t = (s[i] + s[j]) % 256;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement