NotTransform and XorTransform implementations moved to separate file.

This commit is contained in:
morkt
2016-02-29 08:33:17 +04:00
parent 1c96b01677
commit 8d8dae710d
5 changed files with 102 additions and 72 deletions

View File

@@ -83,42 +83,4 @@ namespace GameRes.Formats.X
return new CryptoStream (input, new XorTransform (key), CryptoStreamMode.Read);
}
}
public sealed class XorTransform : ICryptoTransform
{
private const int BlockSize = 256;
private byte m_key;
public bool CanReuseTransform { get { return true; } }
public bool CanTransformMultipleBlocks { get { return true; } }
public int InputBlockSize { get { return BlockSize; } }
public int OutputBlockSize { get { return BlockSize; } }
public XorTransform (byte key)
{
m_key = key;
}
public int TransformBlock (byte[] inputBuffer, int inputOffset, int inputCount,
byte[] outputBuffer, int outputOffset)
{
for (int i = 0; i < inputCount; ++i)
{
outputBuffer[outputOffset++] = (byte)(m_key ^ inputBuffer[inputOffset+i]);
}
return inputCount;
}
public byte[] TransformFinalBlock (byte[] inputBuffer, int inputOffset, int inputCount)
{
byte[] outputBuffer = new byte[inputCount];
TransformBlock (inputBuffer, inputOffset, inputCount, outputBuffer, 0);
return outputBuffer;
}
public void Dispose ()
{
System.GC.SuppressFinalize (this);
}
}
}