public static unsafe void GetHeader(byte[] data, MapleIV iv, ushort majorVer) { fixed(byte *pData = data) { *(ushort *)pData = (ushort)(-(majorVer + 1) ^ iv.HIWORD); *((ushort *)pData + 1) = (ushort)(*(ushort *)pData ^ (data.Length - 4)); } }
public static void Transform(byte[] buffer, MapleIV iv) { int remaining = buffer.Length; int length = 0x5B0; int start = 0; int index; byte[] realIV = new byte[16]; byte[] IVBytes = BitConverter.GetBytes(iv.Value); while (remaining > 0) { for (index = 0; index < realIV.Length; ++index) { realIV[index] = IVBytes[index % 4]; } if (remaining < length) { length = remaining; } for (index = start; index < (start + length); ++index) { int sub = index - start; if ((sub % realIV.Length) == 0) { sTransformer.TransformBlock(realIV); } buffer[index] ^= realIV[sub % realIV.Length]; } start += length; remaining -= length; length = 0x5B4; } iv.Shuffle(); }