Optimizations.
This commit is contained in:
@@ -46,11 +46,11 @@ namespace AssetStudio
|
||||
var keyHigh = BinaryPrimitives.ReadUInt64LittleEndian(key.AsSpan(8, 8));
|
||||
var seed = keyLow ^ keyHigh ^ keySeed ^ blk.InitSeed;
|
||||
|
||||
MT19937_64.Init(seed);
|
||||
var mt64 = new MT19937_64(seed);
|
||||
var xorpad = new byte[KeySize];
|
||||
for (int i = 0; i < KeySize; i += 8)
|
||||
{
|
||||
BinaryPrimitives.WriteUInt64LittleEndian(xorpad.AsSpan(i, 8), MT19937_64.Int64());
|
||||
BinaryPrimitives.WriteUInt64LittleEndian(xorpad.AsSpan(i, 8), mt64.Int64());
|
||||
}
|
||||
|
||||
return new CryptoStream(reader.BaseStream, xorpad);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace AssetStudio
|
||||
{
|
||||
public static class MT19937_64
|
||||
public class MT19937_64
|
||||
{
|
||||
private const ulong N = 312;
|
||||
private const ulong M = 156;
|
||||
@@ -8,10 +8,15 @@
|
||||
private const ulong UPPER_MASK = 0xFFFFFFFF80000000;
|
||||
private const ulong LOWER_MASK = 0X7FFFFFFFUL;
|
||||
|
||||
private static readonly ulong[] mt = new ulong[N + 1];
|
||||
private static ulong mti = N + 1;
|
||||
private readonly ulong[] mt = new ulong[N + 1];
|
||||
private ulong mti = N + 1;
|
||||
|
||||
public static void Init(ulong seed)
|
||||
public MT19937_64(ulong seed)
|
||||
{
|
||||
Init(seed);
|
||||
}
|
||||
|
||||
public void Init(ulong seed)
|
||||
{
|
||||
mt[0] = seed;
|
||||
for (mti = 1; mti < N; mti++)
|
||||
@@ -20,7 +25,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
public static ulong Int64()
|
||||
public ulong Int64()
|
||||
{
|
||||
ulong x;
|
||||
ulong[] mag01 = new ulong[2] { 0x0UL, MATRIX_A };
|
||||
@@ -56,12 +61,12 @@
|
||||
return x;
|
||||
}
|
||||
|
||||
public static long Int63()
|
||||
public long Int63()
|
||||
{
|
||||
return (long)(Int64() >> 1);
|
||||
}
|
||||
|
||||
public static ulong IntN(ulong value)
|
||||
public ulong IntN(ulong value)
|
||||
{
|
||||
return (ulong)Int63() % value;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user