sockscape/server/Encryption/Cipher.cs
2017-05-17 16:06:16 -05:00

38 lines
1,018 B
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CircleScape.Encryption {
class Cipher {
static void ksa(byte[] state, byte[] key) {
int i, j = 0, t;
for(i = 0; i < 256; ++i)
state[i] = (byte)i;
for(i = 0; i < 256; ++i) {
j = (j + state[i] + key[i % key.Length]) % 256;
t = state[i];
state[i] = state[j];
state[j] = (byte)t;
}
}
static void prga(byte[] state, byte[] cipher) {
int i = 0, j = 0, x, t;
for(x = 0; x < cipher.Length; ++x) {
i = (i + 1) % 256;
j = (j + state[i]) % 256;
t = state[i];
state[i] = state[j];
state[j] = (byte)t;
cipher[x] = state[(state[i] + state[j]) % 256];
}
}
// http://bradconte.com/rc4_c
}
}