//
// Licensed under the MIT License. See LICENSE file in the project root for full license information.
//
namespace MUnique.OpenMU.Network.Xor;
///
/// An encryptor which XOR-encrypts data using a 3-byte key.
///
public class Xor3Encryptor : ISpanEncryptor
{
private readonly byte[] _xor3Keys;
private readonly int _startOffset;
///
/// Initializes a new instance of the class.
///
/// The start offset.
public Xor3Encryptor(int startOffset)
{
this._startOffset = startOffset;
this._xor3Keys = DefaultKeys.Xor3Keys;
}
///
public void Encrypt(Span data)
{
this.InternalEncrypt(data.Slice(this._startOffset));
}
///
/// Internal encrypt function. XORs each byte with one byte of the 3-byte key.
///
/// The data.
protected void InternalEncrypt(Span data)
{
for (var i = 0; i < data.Length; i++)
{
data[i] ^= this._xor3Keys[i % 3];
}
}
}