using System;
using FiestaBot;

namespace FiestaBot.Instances.Networking
{
    internal class FiestaCrypto
    {
        public short Xor;

        public FiestaCrypto(short TransferXor) { Xor = TransferXor; }

        public void Crypt(byte[] Buffer, int Start, int Length)
        {
            for (int Counter = 0; Counter < Length; Counter++)
            {
                Buffer[Start + Counter] ^= XorTable[Xor];

                Xor++;

                if (Xor == 499) { Xor = 0; }
            }
        }

        public void Crypt1(byte[] Buffer, int Start, int Length)
        {
            for (int Counter = 0; Counter < Length; Counter++)
            {
                Buffer[Start + Counter] ^= XorTable[Xor];

                Xor--;

                if (Xor == 499) { Xor = 0; }
            }
        }

        private readonly byte[] XorTable = Program.CryptoTable.ToArray();
    }
}
