public static void Encrypt(byte[] buffer, int keyIndex = 0)
{
using (MemoryStream memory = new MemoryStream(Acckey))
{
using (BinaryWriter bin = new BinaryWriter(memory))
{
bin.Seek(1028, SeekOrigin.Begin);
bin.Write((ushort)(keyIndex));
for (int i = 0; i < buffer.Length; i++)
{
byte data = (byte)(buffer ^ Acckey[Acckey[1028] + 4]);
data += Acckey[Acckey[1028] + 516];
data ^= Acckey[Acckey[1029] + 260];
byte data0 = (byte)(data + Acckey[Acckey[1029] + 772]);
data = (byte)(data0 & 15);
data <<= 4;
}
public static void Decrypt(byte[] buffer, int starIndex = 0)
{
using (MemoryStream memory = new MemoryStream(Acckey))
{
using (BinaryWriter bin = new BinaryWriter(memory))
{
bin.Seek(1030, SeekOrigin.Begin);
bin.Write((ushort)(starIndex));//重置key索引
for (int i = starIndex; i < buffer.Length; i++)
{
byte data = (byte)(buffer & 15);
data = (byte)((data << 4) | (buffer >> 4));
data = (byte)(data - Acckey[Acckey[1031] + 772] + 256);
data ^= Acckey[Acckey[1031] + 260];
data = (byte)(data - Acckey[Acckey[1030] + 516] + 256);
buffer = (byte)(data ^ Acckey[Acckey[1030] + 4]);