mirror of
https://github.com/aaru-dps/Aaru.Checksums.git
synced 2025-12-16 19:24:29 +00:00
Reformatted.
This commit is contained in:
@@ -62,7 +62,7 @@ namespace DiscImageChef.Checksums
|
||||
/// <param name="len">Length of buffer to hash.</param>
|
||||
public void Update(byte[] data, uint len)
|
||||
{
|
||||
for (int i = 0; i < len; i++)
|
||||
for(int i = 0; i < len; i++)
|
||||
{
|
||||
sum1 = (ushort)((sum1 + data[i]) % AdlerModule);
|
||||
sum2 = (ushort)((sum2 + sum1) % AdlerModule);
|
||||
@@ -95,7 +95,7 @@ namespace DiscImageChef.Checksums
|
||||
UInt32 finalSum = (uint)((sum2 << 16) | sum1);
|
||||
StringBuilder adlerOutput = new StringBuilder();
|
||||
|
||||
for (int i = 0; i < BigEndianBitConverter.GetBytes(finalSum).Length; i++)
|
||||
for(int i = 0; i < BigEndianBitConverter.GetBytes(finalSum).Length; i++)
|
||||
{
|
||||
adlerOutput.Append(BigEndianBitConverter.GetBytes(finalSum)[i].ToString("x2"));
|
||||
}
|
||||
@@ -137,7 +137,7 @@ namespace DiscImageChef.Checksums
|
||||
|
||||
StringBuilder adlerOutput = new StringBuilder();
|
||||
|
||||
for (int i = 0; i < hash.Length; i++)
|
||||
for(int i = 0; i < hash.Length; i++)
|
||||
{
|
||||
adlerOutput.Append(hash[i].ToString("x2"));
|
||||
}
|
||||
@@ -159,7 +159,7 @@ namespace DiscImageChef.Checksums
|
||||
localSum1 = 1;
|
||||
localSum2 = 0;
|
||||
|
||||
for (int i = 0; i < len; i++)
|
||||
for(int i = 0; i < len; i++)
|
||||
{
|
||||
localSum1 = (ushort)((localSum1 + data[i]) % AdlerModule);
|
||||
localSum2 = (ushort)((localSum2 + localSum1) % AdlerModule);
|
||||
@@ -171,7 +171,7 @@ namespace DiscImageChef.Checksums
|
||||
|
||||
StringBuilder adlerOutput = new StringBuilder();
|
||||
|
||||
for (int i = 0; i < hash.Length; i++)
|
||||
for(int i = 0; i < hash.Length; i++)
|
||||
{
|
||||
adlerOutput.Append(hash[i].ToString("x2"));
|
||||
}
|
||||
|
||||
156
CDChecksums.cs
156
CDChecksums.cs
@@ -50,7 +50,7 @@ namespace DiscImageChef.Checksums
|
||||
|
||||
public static bool? CheckCDSector(byte[] buffer)
|
||||
{
|
||||
switch (buffer.Length)
|
||||
switch(buffer.Length)
|
||||
{
|
||||
case 2448:
|
||||
{
|
||||
@@ -64,15 +64,15 @@ namespace DiscImageChef.Checksums
|
||||
bool? subchannelStatus = CheckCDSectorSubChannel(subchannel);
|
||||
bool? status = null;
|
||||
|
||||
if (channelStatus == null && subchannelStatus == null)
|
||||
if(channelStatus == null && subchannelStatus == null)
|
||||
status = null;
|
||||
if (channelStatus == false || subchannelStatus == false)
|
||||
if(channelStatus == false || subchannelStatus == false)
|
||||
status = false;
|
||||
if (channelStatus == null && subchannelStatus == true)
|
||||
if(channelStatus == null && subchannelStatus == true)
|
||||
status = true;
|
||||
if (channelStatus == true && subchannelStatus == null)
|
||||
if(channelStatus == true && subchannelStatus == null)
|
||||
status = true;
|
||||
if (channelStatus == true && subchannelStatus == true)
|
||||
if(channelStatus == true && subchannelStatus == true)
|
||||
status = true;
|
||||
|
||||
return status;
|
||||
@@ -89,7 +89,7 @@ namespace DiscImageChef.Checksums
|
||||
ECC_F_Table = new byte[256];
|
||||
ECC_B_Table = new byte[256];
|
||||
|
||||
for (UInt32 i = 0; i < 256; i++)
|
||||
for(UInt32 i = 0; i < 256; i++)
|
||||
{
|
||||
UInt32 j = (uint)((i << 1) ^ ((i & 0x80) == 0x80 ? 0x11D : 0));
|
||||
ECC_F_Table[i] = (byte)j;
|
||||
@@ -109,16 +109,16 @@ namespace DiscImageChef.Checksums
|
||||
{
|
||||
UInt32 size = major_count * minor_count;
|
||||
UInt32 major;
|
||||
for (major = 0; major < major_count; major++)
|
||||
for(major = 0; major < major_count; major++)
|
||||
{
|
||||
UInt32 index = (major >> 1) * major_mult + (major & 1);
|
||||
byte ecc_a = 0;
|
||||
byte ecc_b = 0;
|
||||
UInt32 minor;
|
||||
for (minor = 0; minor < minor_count; minor++)
|
||||
for(minor = 0; minor < minor_count; minor++)
|
||||
{
|
||||
byte temp;
|
||||
if (index < 4)
|
||||
if(index < 4)
|
||||
{
|
||||
temp = address[index];
|
||||
}
|
||||
@@ -127,7 +127,7 @@ namespace DiscImageChef.Checksums
|
||||
temp = data[index - 4];
|
||||
}
|
||||
index += minor_inc;
|
||||
if (index >= size)
|
||||
if(index >= size)
|
||||
{
|
||||
index -= size;
|
||||
}
|
||||
@@ -136,7 +136,7 @@ namespace DiscImageChef.Checksums
|
||||
ecc_a = ECC_F_Table[ecc_a];
|
||||
}
|
||||
ecc_a = ECC_B_Table[ECC_F_Table[ecc_a] ^ ecc_b];
|
||||
if (
|
||||
if(
|
||||
ecc[major] != (ecc_a) ||
|
||||
ecc[major + major_count] != (ecc_a ^ ecc_b))
|
||||
{
|
||||
@@ -150,7 +150,7 @@ namespace DiscImageChef.Checksums
|
||||
{
|
||||
ECCInit();
|
||||
|
||||
if (
|
||||
if(
|
||||
channel[0x000] == 0x00 && // sync (12 bytes)
|
||||
channel[0x001] == 0xFF &&
|
||||
channel[0x002] == 0xFF &&
|
||||
@@ -166,12 +166,12 @@ namespace DiscImageChef.Checksums
|
||||
{
|
||||
DicConsole.DebugWriteLine("CD checksums", "Data sector, address {0:X2}:{1:X2}:{2:X2}", channel[0x00C], channel[0x00D], channel[0x00E]);
|
||||
|
||||
if (channel[0x00F] == 0x00) // mode (1 byte)
|
||||
if(channel[0x00F] == 0x00) // mode (1 byte)
|
||||
{
|
||||
DicConsole.DebugWriteLine("CD checksums", "Mode 0 sector at address {0:X2}:{1:X2}:{2:X2}", channel[0x00C], channel[0x00D], channel[0x00E]);
|
||||
for (int i = 0x010; i < 0x930; i++)
|
||||
for(int i = 0x010; i < 0x930; i++)
|
||||
{
|
||||
if (channel[i] != 0x00)
|
||||
if(channel[i] != 0x00)
|
||||
{
|
||||
DicConsole.DebugWriteLine("CD checksums", "Mode 0 sector with error at address: {0:X2}:{1:X2}:{2:X2}", channel[0x00C], channel[0x00D], channel[0x00E]);
|
||||
return false;
|
||||
@@ -179,11 +179,11 @@ namespace DiscImageChef.Checksums
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else if (channel[0x00F] == 0x01) // mode (1 byte)
|
||||
else if(channel[0x00F] == 0x01) // mode (1 byte)
|
||||
{
|
||||
DicConsole.DebugWriteLine("CD checksums", "Mode 1 sector at address {0:X2}:{1:X2}:{2:X2}", channel[0x00C], channel[0x00D], channel[0x00E]);
|
||||
|
||||
if (channel[0x814] != 0x00 || // reserved (8 bytes)
|
||||
if(channel[0x814] != 0x00 || // reserved (8 bytes)
|
||||
channel[0x815] != 0x00 ||
|
||||
channel[0x816] != 0x00 ||
|
||||
channel[0x817] != 0x00 ||
|
||||
@@ -211,12 +211,12 @@ namespace DiscImageChef.Checksums
|
||||
bool FailedECC_P = CheckECC(address, data, 86, 24, 2, 86, ecc_p);
|
||||
bool FailedECC_Q = CheckECC(address, data2, 52, 43, 86, 88, ecc_q);
|
||||
|
||||
if (FailedECC_P)
|
||||
if(FailedECC_P)
|
||||
DicConsole.DebugWriteLine("CD checksums", "Mode 1 sector at address: {0:X2}:{1:X2}:{2:X2}, fails ECC P check", channel[0x00C], channel[0x00D], channel[0x00E]);
|
||||
if (FailedECC_Q)
|
||||
if(FailedECC_Q)
|
||||
DicConsole.DebugWriteLine("CD checksums", "Mode 1 sector at address: {0:X2}:{1:X2}:{2:X2}, fails ECC Q check", channel[0x00C], channel[0x00D], channel[0x00E]);
|
||||
|
||||
if (FailedECC_P || FailedECC_Q)
|
||||
if(FailedECC_P || FailedECC_Q)
|
||||
return false;
|
||||
|
||||
byte[] SectorForCheck = new byte[0x810];
|
||||
@@ -226,7 +226,7 @@ namespace DiscImageChef.Checksums
|
||||
CRC32Context.Data(SectorForCheck, 0x810, out CalculatedEDCBytes, CDCRC32Poly, CDCRC32Seed);
|
||||
UInt32 CalculatedEDC = BitConverter.ToUInt32(CalculatedEDCBytes, 0);
|
||||
|
||||
if (CalculatedEDC != StoredEDC)
|
||||
if(CalculatedEDC != StoredEDC)
|
||||
{
|
||||
DicConsole.DebugWriteLine("CD checksums", "Mode 1 sector at address: {0:X2}:{1:X2}:{2:X2}, got CRC 0x{3:X8} expected 0x{4:X8}", channel[0x00C], channel[0x00D], channel[0x00E], CalculatedEDC, StoredEDC);
|
||||
return false;
|
||||
@@ -234,13 +234,13 @@ namespace DiscImageChef.Checksums
|
||||
|
||||
return true;
|
||||
}
|
||||
else if (channel[0x00F] == 0x02) // mode (1 byte)
|
||||
else if(channel[0x00F] == 0x02) // mode (1 byte)
|
||||
{
|
||||
DicConsole.DebugWriteLine("CD checksums", "Mode 2 sector at address {0:X2}:{1:X2}:{2:X2}", channel[0x00C], channel[0x00D], channel[0x00E]);
|
||||
|
||||
if ((channel[0x012] & 0x20) == 0x20) // mode 2 form 2
|
||||
if((channel[0x012] & 0x20) == 0x20) // mode 2 form 2
|
||||
{
|
||||
if (channel[0x010] != channel[0x014] || channel[0x011] != channel[0x015] || channel[0x012] != channel[0x016] || channel[0x013] != channel[0x017])
|
||||
if(channel[0x010] != channel[0x014] || channel[0x011] != channel[0x015] || channel[0x012] != channel[0x016] || channel[0x013] != channel[0x017])
|
||||
{
|
||||
DicConsole.DebugWriteLine("CD checksums", "Subheader copies differ in mode 2 form 2 sector at address: {0:X2}:{1:X2}:{2:X2}", channel[0x00C], channel[0x00D], channel[0x00E]);
|
||||
}
|
||||
@@ -252,7 +252,7 @@ namespace DiscImageChef.Checksums
|
||||
CRC32Context.Data(SectorForCheck, 0x91C, out CalculatedEDCBytes, CDCRC32Poly, CDCRC32Seed);
|
||||
UInt32 CalculatedEDC = BitConverter.ToUInt32(CalculatedEDCBytes, 0);
|
||||
|
||||
if (CalculatedEDC != StoredEDC && StoredEDC != 0x00000000)
|
||||
if(CalculatedEDC != StoredEDC && StoredEDC != 0x00000000)
|
||||
{
|
||||
DicConsole.DebugWriteLine("CD checksums", "Mode 2 form 2 sector at address: {0:X2}:{1:X2}:{2:X2}, got CRC 0x{3:X8} expected 0x{4:X8}", channel[0x00C], channel[0x00D], channel[0x00E], CalculatedEDC, StoredEDC);
|
||||
return false;
|
||||
@@ -260,7 +260,7 @@ namespace DiscImageChef.Checksums
|
||||
}
|
||||
else
|
||||
{
|
||||
if (channel[0x010] != channel[0x014] || channel[0x011] != channel[0x015] || channel[0x012] != channel[0x016] || channel[0x013] != channel[0x017])
|
||||
if(channel[0x010] != channel[0x014] || channel[0x011] != channel[0x015] || channel[0x012] != channel[0x016] || channel[0x013] != channel[0x017])
|
||||
{
|
||||
DicConsole.DebugWriteLine("CD checksums", "Subheader copies differ in mode 2 form 1 sector at address: {0:X2}:{1:X2}:{2:X2}", channel[0x00C], channel[0x00D], channel[0x00E]);
|
||||
}
|
||||
@@ -283,12 +283,12 @@ namespace DiscImageChef.Checksums
|
||||
bool FailedECC_P = CheckECC(address, data, 86, 24, 2, 86, ecc_p);
|
||||
bool FailedECC_Q = CheckECC(address, data2, 52, 43, 86, 88, ecc_q);
|
||||
|
||||
if (FailedECC_P)
|
||||
if(FailedECC_P)
|
||||
DicConsole.DebugWriteLine("CD checksums", "Mode 2 form 1 sector at address: {0:X2}:{1:X2}:{2:X2}, fails ECC P check", channel[0x00C], channel[0x00D], channel[0x00E]);
|
||||
if (FailedECC_Q)
|
||||
if(FailedECC_Q)
|
||||
DicConsole.DebugWriteLine("CD checksums", "Mode 2 form 1 sector at address: {0:X2}:{1:X2}:{2:X2}, fails ECC Q check", channel[0x00F], channel[0x00C], channel[0x00D], channel[0x00E]);
|
||||
|
||||
if (FailedECC_P || FailedECC_Q)
|
||||
if(FailedECC_P || FailedECC_Q)
|
||||
return false;
|
||||
|
||||
byte[] SectorForCheck = new byte[0x808];
|
||||
@@ -298,7 +298,7 @@ namespace DiscImageChef.Checksums
|
||||
CRC32Context.Data(SectorForCheck, 0x808, out CalculatedEDCBytes, CDCRC32Poly, CDCRC32Seed);
|
||||
UInt32 CalculatedEDC = BitConverter.ToUInt32(CalculatedEDCBytes, 0);
|
||||
|
||||
if (CalculatedEDC != StoredEDC)
|
||||
if(CalculatedEDC != StoredEDC)
|
||||
{
|
||||
DicConsole.DebugWriteLine("CD checksums", "Mode 2 form 1 sector at address: {0:X2}:{1:X2}:{2:X2}, got CRC 0x{3:X8} expected 0x{4:X8}", channel[0x00C], channel[0x00D], channel[0x00E], CalculatedEDC, StoredEDC);
|
||||
return false;
|
||||
@@ -330,16 +330,16 @@ namespace DiscImageChef.Checksums
|
||||
byte[] CDSubRWPack4 = new byte[24];
|
||||
|
||||
int i = 0;
|
||||
for (int j = 0; j < 12; j++)
|
||||
for(int j = 0; j < 12; j++)
|
||||
QSubChannel[j] = 0;
|
||||
for (int j = 0; j < 18; j++)
|
||||
for(int j = 0; j < 18; j++)
|
||||
{
|
||||
CDTextPack1[j] = 0;
|
||||
CDTextPack2[j] = 0;
|
||||
CDTextPack3[j] = 0;
|
||||
CDTextPack4[j] = 0;
|
||||
}
|
||||
for (int j = 0; j < 24; j++)
|
||||
for(int j = 0; j < 24; j++)
|
||||
{
|
||||
CDSubRWPack1[j] = 0;
|
||||
CDSubRWPack2[j] = 0;
|
||||
@@ -347,7 +347,7 @@ namespace DiscImageChef.Checksums
|
||||
CDSubRWPack4[j] = 0;
|
||||
}
|
||||
|
||||
for (int j = 0; j < 12; j++)
|
||||
for(int j = 0; j < 12; j++)
|
||||
{
|
||||
QSubChannel[j] = (byte)(QSubChannel[j] | ((subchannel[i++] & 0x40) << 1));
|
||||
QSubChannel[j] = (byte)(QSubChannel[j] | (subchannel[i++] & 0x40));
|
||||
@@ -360,86 +360,86 @@ namespace DiscImageChef.Checksums
|
||||
}
|
||||
|
||||
i = 0;
|
||||
for (int j = 0; j < 18; j++)
|
||||
for(int j = 0; j < 18; j++)
|
||||
{
|
||||
if (j < 18)
|
||||
if(j < 18)
|
||||
CDTextPack1[j] = (byte)(CDTextPack1[j] | ((subchannel[i++] & 0x3F) << 2));
|
||||
if (j < 18)
|
||||
if(j < 18)
|
||||
CDTextPack1[j] = (byte)(CDTextPack1[j++] | ((subchannel[i] & 0xC0) >> 4));
|
||||
if (j < 18)
|
||||
if(j < 18)
|
||||
CDTextPack1[j] = (byte)(CDTextPack1[j] | ((subchannel[i++] & 0x0F) << 4));
|
||||
if (j < 18)
|
||||
if(j < 18)
|
||||
CDTextPack1[j] = (byte)(CDTextPack1[j++] | ((subchannel[i] & 0x3C) >> 2));
|
||||
if (j < 18)
|
||||
if(j < 18)
|
||||
CDTextPack1[j] = (byte)(CDTextPack1[j] | ((subchannel[i++] & 0x03) << 6));
|
||||
if (j < 18)
|
||||
if(j < 18)
|
||||
CDTextPack1[j] = (byte)(CDTextPack1[j] | (subchannel[i++] & 0x3F));
|
||||
}
|
||||
for (int j = 0; j < 18; j++)
|
||||
for(int j = 0; j < 18; j++)
|
||||
{
|
||||
if (j < 18)
|
||||
if(j < 18)
|
||||
CDTextPack2[j] = (byte)(CDTextPack2[j] | ((subchannel[i++] & 0x3F) << 2));
|
||||
if (j < 18)
|
||||
if(j < 18)
|
||||
CDTextPack2[j] = (byte)(CDTextPack2[j++] | ((subchannel[i] & 0xC0) >> 4));
|
||||
if (j < 18)
|
||||
if(j < 18)
|
||||
CDTextPack2[j] = (byte)(CDTextPack2[j] | ((subchannel[i++] & 0x0F) << 4));
|
||||
if (j < 18)
|
||||
if(j < 18)
|
||||
CDTextPack2[j] = (byte)(CDTextPack2[j++] | ((subchannel[i] & 0x3C) >> 2));
|
||||
if (j < 18)
|
||||
if(j < 18)
|
||||
CDTextPack2[j] = (byte)(CDTextPack2[j] | ((subchannel[i++] & 0x03) << 6));
|
||||
if (j < 18)
|
||||
if(j < 18)
|
||||
CDTextPack2[j] = (byte)(CDTextPack2[j] | (subchannel[i++] & 0x3F));
|
||||
}
|
||||
for (int j = 0; j < 18; j++)
|
||||
for(int j = 0; j < 18; j++)
|
||||
{
|
||||
if (j < 18)
|
||||
if(j < 18)
|
||||
CDTextPack3[j] = (byte)(CDTextPack3[j] | ((subchannel[i++] & 0x3F) << 2));
|
||||
if (j < 18)
|
||||
if(j < 18)
|
||||
CDTextPack3[j] = (byte)(CDTextPack3[j++] | ((subchannel[i] & 0xC0) >> 4));
|
||||
if (j < 18)
|
||||
if(j < 18)
|
||||
CDTextPack3[j] = (byte)(CDTextPack3[j] | ((subchannel[i++] & 0x0F) << 4));
|
||||
if (j < 18)
|
||||
if(j < 18)
|
||||
CDTextPack3[j] = (byte)(CDTextPack3[j++] | ((subchannel[i] & 0x3C) >> 2));
|
||||
if (j < 18)
|
||||
if(j < 18)
|
||||
CDTextPack3[j] = (byte)(CDTextPack3[j] | ((subchannel[i++] & 0x03) << 6));
|
||||
if (j < 18)
|
||||
if(j < 18)
|
||||
CDTextPack3[j] = (byte)(CDTextPack3[j] | (subchannel[i++] & 0x3F));
|
||||
}
|
||||
for (int j = 0; j < 18; j++)
|
||||
for(int j = 0; j < 18; j++)
|
||||
{
|
||||
if (j < 18)
|
||||
if(j < 18)
|
||||
CDTextPack4[j] = (byte)(CDTextPack4[j] | ((subchannel[i++] & 0x3F) << 2));
|
||||
if (j < 18)
|
||||
if(j < 18)
|
||||
CDTextPack4[j] = (byte)(CDTextPack4[j++] | ((subchannel[i] & 0xC0) >> 4));
|
||||
if (j < 18)
|
||||
if(j < 18)
|
||||
CDTextPack4[j] = (byte)(CDTextPack4[j] | ((subchannel[i++] & 0x0F) << 4));
|
||||
if (j < 18)
|
||||
if(j < 18)
|
||||
CDTextPack4[j] = (byte)(CDTextPack4[j++] | ((subchannel[i] & 0x3C) >> 2));
|
||||
if (j < 18)
|
||||
if(j < 18)
|
||||
CDTextPack4[j] = (byte)(CDTextPack4[j] | ((subchannel[i++] & 0x03) << 6));
|
||||
if (j < 18)
|
||||
if(j < 18)
|
||||
CDTextPack4[j] = (byte)(CDTextPack4[j] | (subchannel[i++] & 0x3F));
|
||||
}
|
||||
|
||||
i = 0;
|
||||
for (int j = 0; j < 24; j++)
|
||||
for(int j = 0; j < 24; j++)
|
||||
{
|
||||
CDSubRWPack1[j] = (byte)(subchannel[i++] & 0x3F);
|
||||
}
|
||||
for (int j = 0; j < 24; j++)
|
||||
for(int j = 0; j < 24; j++)
|
||||
{
|
||||
CDSubRWPack2[j] = (byte)(subchannel[i++] & 0x3F);
|
||||
}
|
||||
for (int j = 0; j < 24; j++)
|
||||
for(int j = 0; j < 24; j++)
|
||||
{
|
||||
CDSubRWPack3[j] = (byte)(subchannel[i++] & 0x3F);
|
||||
}
|
||||
for (int j = 0; j < 24; j++)
|
||||
for(int j = 0; j < 24; j++)
|
||||
{
|
||||
CDSubRWPack4[j] = (byte)(subchannel[i++] & 0x3F);
|
||||
}
|
||||
|
||||
switch (CDSubRWPack1[0])
|
||||
switch(CDSubRWPack1[0])
|
||||
{
|
||||
case 0x00:
|
||||
DicConsole.DebugWriteLine("CD checksums", "Detected Zero Pack in subchannel");
|
||||
@@ -474,27 +474,27 @@ namespace DiscImageChef.Checksums
|
||||
Array.Copy(QSubChannel, 0, QSubChannelForCRC, 0, 10);
|
||||
UInt16 CalculatedQCRC = CalculateCCITT_CRC16(QSubChannelForCRC);
|
||||
|
||||
if (QSubChannelCRC != CalculatedQCRC)
|
||||
if(QSubChannelCRC != CalculatedQCRC)
|
||||
{
|
||||
DicConsole.DebugWriteLine("CD checksums", "Q subchannel CRC 0x{0:X4}, expected 0x{1:X4}", CalculatedQCRC, QSubChannelCRC);
|
||||
status = false;
|
||||
}
|
||||
|
||||
if ((CDTextPack1[0] & 0x80) == 0x80)
|
||||
if((CDTextPack1[0] & 0x80) == 0x80)
|
||||
{
|
||||
UInt16 CDTextPack1CRC = BigEndianBitConverter.ToUInt16(CDTextPack1, 16);
|
||||
byte[] CDTextPack1ForCRC = new byte[16];
|
||||
Array.Copy(CDTextPack1, 0, CDTextPack1ForCRC, 0, 16);
|
||||
UInt16 CalculatedCDTP1CRC = CalculateCCITT_CRC16(CDTextPack1ForCRC);
|
||||
|
||||
if (CDTextPack1CRC != CalculatedCDTP1CRC && CDTextPack1CRC != 0)
|
||||
if(CDTextPack1CRC != CalculatedCDTP1CRC && CDTextPack1CRC != 0)
|
||||
{
|
||||
DicConsole.DebugWriteLine("CD checksums", "CD-Text Pack 1 CRC 0x{0:X4}, expected 0x{1:X4}", CDTextPack1CRC, CalculatedCDTP1CRC);
|
||||
status = false;
|
||||
}
|
||||
}
|
||||
|
||||
if ((CDTextPack2[0] & 0x80) == 0x80)
|
||||
if((CDTextPack2[0] & 0x80) == 0x80)
|
||||
{
|
||||
UInt16 CDTextPack2CRC = BigEndianBitConverter.ToUInt16(CDTextPack2, 16);
|
||||
byte[] CDTextPack2ForCRC = new byte[16];
|
||||
@@ -502,14 +502,14 @@ namespace DiscImageChef.Checksums
|
||||
UInt16 CalculatedCDTP2CRC = CalculateCCITT_CRC16(CDTextPack2ForCRC);
|
||||
DicConsole.DebugWriteLine("CD checksums", "Cyclic CDTP2 0x{0:X4}, Calc CDTP2 0x{1:X4}", CDTextPack2CRC, CalculatedCDTP2CRC);
|
||||
|
||||
if (CDTextPack2CRC != CalculatedCDTP2CRC && CDTextPack2CRC != 0)
|
||||
if(CDTextPack2CRC != CalculatedCDTP2CRC && CDTextPack2CRC != 0)
|
||||
{
|
||||
DicConsole.DebugWriteLine("CD checksums", "CD-Text Pack 2 CRC 0x{0:X4}, expected 0x{1:X4}", CDTextPack2CRC, CalculatedCDTP2CRC);
|
||||
status = false;
|
||||
}
|
||||
}
|
||||
|
||||
if ((CDTextPack3[0] & 0x80) == 0x80)
|
||||
if((CDTextPack3[0] & 0x80) == 0x80)
|
||||
{
|
||||
UInt16 CDTextPack3CRC = BigEndianBitConverter.ToUInt16(CDTextPack3, 16);
|
||||
byte[] CDTextPack3ForCRC = new byte[16];
|
||||
@@ -517,14 +517,14 @@ namespace DiscImageChef.Checksums
|
||||
UInt16 CalculatedCDTP3CRC = CalculateCCITT_CRC16(CDTextPack3ForCRC);
|
||||
DicConsole.DebugWriteLine("CD checksums", "Cyclic CDTP3 0x{0:X4}, Calc CDTP3 0x{1:X4}", CDTextPack3CRC, CalculatedCDTP3CRC);
|
||||
|
||||
if (CDTextPack3CRC != CalculatedCDTP3CRC && CDTextPack3CRC != 0)
|
||||
if(CDTextPack3CRC != CalculatedCDTP3CRC && CDTextPack3CRC != 0)
|
||||
{
|
||||
DicConsole.DebugWriteLine("CD checksums", "CD-Text Pack 3 CRC 0x{0:X4}, expected 0x{1:X4}", CDTextPack3CRC, CalculatedCDTP3CRC);
|
||||
status = false;
|
||||
}
|
||||
}
|
||||
|
||||
if ((CDTextPack4[0] & 0x80) == 0x80)
|
||||
if((CDTextPack4[0] & 0x80) == 0x80)
|
||||
{
|
||||
UInt16 CDTextPack4CRC = BigEndianBitConverter.ToUInt16(CDTextPack4, 16);
|
||||
byte[] CDTextPack4ForCRC = new byte[16];
|
||||
@@ -532,7 +532,7 @@ namespace DiscImageChef.Checksums
|
||||
UInt16 CalculatedCDTP4CRC = CalculateCCITT_CRC16(CDTextPack4ForCRC);
|
||||
DicConsole.DebugWriteLine("CD checksums", "Cyclic CDTP4 0x{0:X4}, Calc CDTP4 0x{1:X4}", CDTextPack4CRC, CalculatedCDTP4CRC);
|
||||
|
||||
if (CDTextPack4CRC != CalculatedCDTP4CRC && CDTextPack4CRC != 0)
|
||||
if(CDTextPack4CRC != CalculatedCDTP4CRC && CDTextPack4CRC != 0)
|
||||
{
|
||||
DicConsole.DebugWriteLine("CD checksums", "CD-Text Pack 4 CRC 0x{0:X4}, expected 0x{1:X4}", CDTextPack4CRC, CalculatedCDTP4CRC);
|
||||
status = false;
|
||||
@@ -581,7 +581,7 @@ namespace DiscImageChef.Checksums
|
||||
static ushort CalculateCCITT_CRC16(byte[] buffer)
|
||||
{
|
||||
UInt16 CRC16 = 0;
|
||||
for (int i = 0; i < buffer.Length; i++)
|
||||
for(int i = 0; i < buffer.Length; i++)
|
||||
{
|
||||
CRC16 = (ushort)(CCITT_CRC16Table[(CRC16 >> 8) ^ buffer[i]] ^ (CRC16 << 8));
|
||||
}
|
||||
|
||||
@@ -60,11 +60,11 @@ namespace DiscImageChef.Checksums
|
||||
hashInt = crc16Seed;
|
||||
|
||||
table = new UInt16[256];
|
||||
for (int i = 0; i < 256; i++)
|
||||
for(int i = 0; i < 256; i++)
|
||||
{
|
||||
UInt16 entry = (UInt16)i;
|
||||
for (int j = 0; j < 8; j++)
|
||||
if ((entry & 1) == 1)
|
||||
for(int j = 0; j < 8; j++)
|
||||
if((entry & 1) == 1)
|
||||
entry = (ushort)((entry >> 1) ^ crc16Poly);
|
||||
else
|
||||
entry = (ushort)(entry >> 1);
|
||||
@@ -79,7 +79,7 @@ namespace DiscImageChef.Checksums
|
||||
/// <param name="len">Length of buffer to hash.</param>
|
||||
public void Update(byte[] data, uint len)
|
||||
{
|
||||
for (int i = 0; i < len; i++)
|
||||
for(int i = 0; i < len; i++)
|
||||
hashInt = (ushort)((hashInt >> 8) ^ table[data[i] ^ (hashInt & 0xFF)]);
|
||||
}
|
||||
|
||||
@@ -111,7 +111,7 @@ namespace DiscImageChef.Checksums
|
||||
StringBuilder crc16Output = new StringBuilder();
|
||||
|
||||
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
|
||||
for (int i = 0; i < BigEndianBitConverter.GetBytes(hashInt).Length; i++)
|
||||
for(int i = 0; i < BigEndianBitConverter.GetBytes(hashInt).Length; i++)
|
||||
{
|
||||
crc16Output.Append(BigEndianBitConverter.GetBytes(hashInt)[i].ToString("x2"));
|
||||
}
|
||||
@@ -144,18 +144,18 @@ namespace DiscImageChef.Checksums
|
||||
localhashInt = crc16Seed;
|
||||
|
||||
localTable = new UInt16[256];
|
||||
for (int i = 0; i < 256; i++)
|
||||
for(int i = 0; i < 256; i++)
|
||||
{
|
||||
UInt16 entry = (UInt16)i;
|
||||
for (int j = 0; j < 8; j++)
|
||||
if ((entry & 1) == 1)
|
||||
for(int j = 0; j < 8; j++)
|
||||
if((entry & 1) == 1)
|
||||
entry = (ushort)((entry >> 1) ^ crc16Poly);
|
||||
else
|
||||
entry = (ushort)(entry >> 1);
|
||||
localTable[i] = entry;
|
||||
}
|
||||
|
||||
for (int i = 0; i < fileStream.Length; i++)
|
||||
for(int i = 0; i < fileStream.Length; i++)
|
||||
localhashInt = (ushort)((localhashInt >> 8) ^ localTable[fileStream.ReadByte() ^ localhashInt & 0xff]);
|
||||
|
||||
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
|
||||
@@ -163,7 +163,7 @@ namespace DiscImageChef.Checksums
|
||||
|
||||
StringBuilder crc16Output = new StringBuilder();
|
||||
|
||||
for (int i = 0; i < hash.Length; i++)
|
||||
for(int i = 0; i < hash.Length; i++)
|
||||
{
|
||||
crc16Output.Append(hash[i].ToString("x2"));
|
||||
}
|
||||
@@ -198,18 +198,18 @@ namespace DiscImageChef.Checksums
|
||||
localhashInt = seed;
|
||||
|
||||
localTable = new UInt16[256];
|
||||
for (int i = 0; i < 256; i++)
|
||||
for(int i = 0; i < 256; i++)
|
||||
{
|
||||
UInt16 entry = (UInt16)i;
|
||||
for (int j = 0; j < 8; j++)
|
||||
if ((entry & 1) == 1)
|
||||
for(int j = 0; j < 8; j++)
|
||||
if((entry & 1) == 1)
|
||||
entry = (ushort)((entry >> 1) ^ polynomial);
|
||||
else
|
||||
entry = (ushort)(entry >> 1);
|
||||
localTable[i] = entry;
|
||||
}
|
||||
|
||||
for (int i = 0; i < len; i++)
|
||||
for(int i = 0; i < len; i++)
|
||||
localhashInt = (ushort)((localhashInt >> 8) ^ localTable[data[i] ^ localhashInt & 0xff]);
|
||||
|
||||
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
|
||||
@@ -217,7 +217,7 @@ namespace DiscImageChef.Checksums
|
||||
|
||||
StringBuilder crc16Output = new StringBuilder();
|
||||
|
||||
for (int i = 0; i < hash.Length; i++)
|
||||
for(int i = 0; i < hash.Length; i++)
|
||||
{
|
||||
crc16Output.Append(hash[i].ToString("x2"));
|
||||
}
|
||||
|
||||
@@ -60,11 +60,11 @@ namespace DiscImageChef.Checksums
|
||||
hashInt = crc32Seed;
|
||||
|
||||
table = new UInt32[256];
|
||||
for (int i = 0; i < 256; i++)
|
||||
for(int i = 0; i < 256; i++)
|
||||
{
|
||||
UInt32 entry = (UInt32)i;
|
||||
for (int j = 0; j < 8; j++)
|
||||
if ((entry & 1) == 1)
|
||||
for(int j = 0; j < 8; j++)
|
||||
if((entry & 1) == 1)
|
||||
entry = (entry >> 1) ^ crc32Poly;
|
||||
else
|
||||
entry = entry >> 1;
|
||||
@@ -79,7 +79,7 @@ namespace DiscImageChef.Checksums
|
||||
/// <param name="len">Length of buffer to hash.</param>
|
||||
public void Update(byte[] data, uint len)
|
||||
{
|
||||
for (int i = 0; i < len; i++)
|
||||
for(int i = 0; i < len; i++)
|
||||
hashInt = (hashInt >> 8) ^ table[data[i] ^ hashInt & 0xff];
|
||||
}
|
||||
|
||||
@@ -111,7 +111,7 @@ namespace DiscImageChef.Checksums
|
||||
StringBuilder crc32Output = new StringBuilder();
|
||||
|
||||
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
|
||||
for (int i = 0; i < BigEndianBitConverter.GetBytes(hashInt).Length; i++)
|
||||
for(int i = 0; i < BigEndianBitConverter.GetBytes(hashInt).Length; i++)
|
||||
{
|
||||
crc32Output.Append(BigEndianBitConverter.GetBytes(hashInt)[i].ToString("x2"));
|
||||
}
|
||||
@@ -144,18 +144,18 @@ namespace DiscImageChef.Checksums
|
||||
localhashInt = crc32Seed;
|
||||
|
||||
localTable = new UInt32[256];
|
||||
for (int i = 0; i < 256; i++)
|
||||
for(int i = 0; i < 256; i++)
|
||||
{
|
||||
UInt32 entry = (UInt32)i;
|
||||
for (int j = 0; j < 8; j++)
|
||||
if ((entry & 1) == 1)
|
||||
for(int j = 0; j < 8; j++)
|
||||
if((entry & 1) == 1)
|
||||
entry = (entry >> 1) ^ crc32Poly;
|
||||
else
|
||||
entry = entry >> 1;
|
||||
localTable[i] = entry;
|
||||
}
|
||||
|
||||
for (int i = 0; i < fileStream.Length; i++)
|
||||
for(int i = 0; i < fileStream.Length; i++)
|
||||
localhashInt = (localhashInt >> 8) ^ localTable[fileStream.ReadByte() ^ localhashInt & 0xff];
|
||||
|
||||
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
|
||||
@@ -163,7 +163,7 @@ namespace DiscImageChef.Checksums
|
||||
|
||||
StringBuilder crc32Output = new StringBuilder();
|
||||
|
||||
for (int i = 0; i < hash.Length; i++)
|
||||
for(int i = 0; i < hash.Length; i++)
|
||||
{
|
||||
crc32Output.Append(hash[i].ToString("x2"));
|
||||
}
|
||||
@@ -198,18 +198,18 @@ namespace DiscImageChef.Checksums
|
||||
localhashInt = seed;
|
||||
|
||||
localTable = new UInt32[256];
|
||||
for (int i = 0; i < 256; i++)
|
||||
for(int i = 0; i < 256; i++)
|
||||
{
|
||||
UInt32 entry = (UInt32)i;
|
||||
for (int j = 0; j < 8; j++)
|
||||
if ((entry & 1) == 1)
|
||||
for(int j = 0; j < 8; j++)
|
||||
if((entry & 1) == 1)
|
||||
entry = (entry >> 1) ^ polynomial;
|
||||
else
|
||||
entry = entry >> 1;
|
||||
localTable[i] = entry;
|
||||
}
|
||||
|
||||
for (int i = 0; i < len; i++)
|
||||
for(int i = 0; i < len; i++)
|
||||
localhashInt = (localhashInt >> 8) ^ localTable[data[i] ^ localhashInt & 0xff];
|
||||
|
||||
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
|
||||
@@ -217,7 +217,7 @@ namespace DiscImageChef.Checksums
|
||||
|
||||
StringBuilder crc32Output = new StringBuilder();
|
||||
|
||||
for (int i = 0; i < hash.Length; i++)
|
||||
for(int i = 0; i < hash.Length; i++)
|
||||
{
|
||||
crc32Output.Append(hash[i].ToString("x2"));
|
||||
}
|
||||
|
||||
@@ -59,11 +59,11 @@ namespace DiscImageChef.Checksums
|
||||
hashInt = crc64Seed;
|
||||
|
||||
table = new UInt64[256];
|
||||
for (int i = 0; i < 256; i++)
|
||||
for(int i = 0; i < 256; i++)
|
||||
{
|
||||
UInt64 entry = (UInt64)i;
|
||||
for (int j = 0; j < 8; j++)
|
||||
if ((entry & 1) == 1)
|
||||
for(int j = 0; j < 8; j++)
|
||||
if((entry & 1) == 1)
|
||||
entry = (entry >> 1) ^ crc64Poly;
|
||||
else
|
||||
entry = entry >> 1;
|
||||
@@ -78,7 +78,7 @@ namespace DiscImageChef.Checksums
|
||||
/// <param name="len">Length of buffer to hash.</param>
|
||||
public void Update(byte[] data, uint len)
|
||||
{
|
||||
for (int i = 0; i < len; i++)
|
||||
for(int i = 0; i < len; i++)
|
||||
hashInt = (hashInt >> 8) ^ table[data[i] ^ hashInt & 0xff];
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ namespace DiscImageChef.Checksums
|
||||
StringBuilder crc64Output = new StringBuilder();
|
||||
|
||||
BigEndianBitConverter.IsLittleEndian = BigEndianBitConverter.IsLittleEndian;
|
||||
for (int i = 0; i < BigEndianBitConverter.GetBytes(hashInt).Length; i++)
|
||||
for(int i = 0; i < BigEndianBitConverter.GetBytes(hashInt).Length; i++)
|
||||
{
|
||||
crc64Output.Append(BigEndianBitConverter.GetBytes(hashInt)[i].ToString("x2"));
|
||||
}
|
||||
@@ -143,18 +143,18 @@ namespace DiscImageChef.Checksums
|
||||
localhashInt = crc64Seed;
|
||||
|
||||
localTable = new UInt64[256];
|
||||
for (int i = 0; i < 256; i++)
|
||||
for(int i = 0; i < 256; i++)
|
||||
{
|
||||
UInt64 entry = (UInt64)i;
|
||||
for (int j = 0; j < 8; j++)
|
||||
if ((entry & 1) == 1)
|
||||
for(int j = 0; j < 8; j++)
|
||||
if((entry & 1) == 1)
|
||||
entry = (entry >> 1) ^ crc64Poly;
|
||||
else
|
||||
entry = entry >> 1;
|
||||
localTable[i] = entry;
|
||||
}
|
||||
|
||||
for (int i = 0; i < fileStream.Length; i++)
|
||||
for(int i = 0; i < fileStream.Length; i++)
|
||||
localhashInt = (localhashInt >> 8) ^ localTable[(ulong)fileStream.ReadByte() ^ localhashInt & (ulong)0xff];
|
||||
|
||||
BigEndianBitConverter.IsLittleEndian = BigEndianBitConverter.IsLittleEndian;
|
||||
@@ -162,7 +162,7 @@ namespace DiscImageChef.Checksums
|
||||
|
||||
StringBuilder crc64Output = new StringBuilder();
|
||||
|
||||
for (int i = 0; i < hash.Length; i++)
|
||||
for(int i = 0; i < hash.Length; i++)
|
||||
{
|
||||
crc64Output.Append(hash[i].ToString("x2"));
|
||||
}
|
||||
@@ -197,18 +197,18 @@ namespace DiscImageChef.Checksums
|
||||
localhashInt = seed;
|
||||
|
||||
localTable = new UInt64[256];
|
||||
for (int i = 0; i < 256; i++)
|
||||
for(int i = 0; i < 256; i++)
|
||||
{
|
||||
UInt64 entry = (UInt64)i;
|
||||
for (int j = 0; j < 8; j++)
|
||||
if ((entry & 1) == 1)
|
||||
for(int j = 0; j < 8; j++)
|
||||
if((entry & 1) == 1)
|
||||
entry = (entry >> 1) ^ polynomial;
|
||||
else
|
||||
entry = entry >> 1;
|
||||
localTable[i] = entry;
|
||||
}
|
||||
|
||||
for (int i = 0; i < len; i++)
|
||||
for(int i = 0; i < len; i++)
|
||||
localhashInt = (localhashInt >> 8) ^ localTable[data[i] ^ localhashInt & 0xff];
|
||||
|
||||
BigEndianBitConverter.IsLittleEndian = BigEndianBitConverter.IsLittleEndian;
|
||||
@@ -216,7 +216,7 @@ namespace DiscImageChef.Checksums
|
||||
|
||||
StringBuilder crc64Output = new StringBuilder();
|
||||
|
||||
for (int i = 0; i < hash.Length; i++)
|
||||
for(int i = 0; i < hash.Length; i++)
|
||||
{
|
||||
crc64Output.Append(hash[i].ToString("x2"));
|
||||
}
|
||||
|
||||
@@ -69,15 +69,15 @@ namespace DiscImageChef.Checksums
|
||||
public void Update(byte[] data, uint len)
|
||||
{
|
||||
UInt16 block;
|
||||
if (!inodd)
|
||||
if(!inodd)
|
||||
{
|
||||
// Odd size
|
||||
if (len % 2 != 0)
|
||||
if(len % 2 != 0)
|
||||
{
|
||||
oddValue = data[len - 1];
|
||||
inodd = true;
|
||||
|
||||
for (int i = 0; i < len - 1; i += 2)
|
||||
for(int i = 0; i < len - 1; i += 2)
|
||||
{
|
||||
block = BigEndianBitConverter.ToUInt16(data, i);
|
||||
sum1 = (UInt16)((sum1 + block) % 0xFFFF);
|
||||
@@ -87,7 +87,7 @@ namespace DiscImageChef.Checksums
|
||||
else
|
||||
{
|
||||
inodd = false;
|
||||
for (int i = 0; i < len; i += 2)
|
||||
for(int i = 0; i < len; i += 2)
|
||||
{
|
||||
block = BigEndianBitConverter.ToUInt16(data, i);
|
||||
sum1 = (UInt16)((sum1 + block) % 0xFFFF);
|
||||
@@ -107,12 +107,12 @@ namespace DiscImageChef.Checksums
|
||||
sum2 = (UInt16)((sum2 + sum1) % 0xFFFF);
|
||||
|
||||
// Even size, carrying odd
|
||||
if (len % 2 == 0)
|
||||
if(len % 2 == 0)
|
||||
{
|
||||
oddValue = data[len - 1];
|
||||
inodd = true;
|
||||
|
||||
for (int i = 1; i < len - 1; i += 2)
|
||||
for(int i = 1; i < len - 1; i += 2)
|
||||
{
|
||||
block = BigEndianBitConverter.ToUInt16(data, i);
|
||||
sum1 = (UInt16)((sum1 + block) % 0xFFFF);
|
||||
@@ -122,7 +122,7 @@ namespace DiscImageChef.Checksums
|
||||
else
|
||||
{
|
||||
inodd = false;
|
||||
for (int i = 1; i < len; i += 2)
|
||||
for(int i = 1; i < len; i += 2)
|
||||
{
|
||||
block = BigEndianBitConverter.ToUInt16(data, i);
|
||||
sum1 = (UInt16)((sum1 + block) % 0xFFFF);
|
||||
@@ -158,7 +158,7 @@ namespace DiscImageChef.Checksums
|
||||
UInt32 finalSum = (UInt32)(sum1 + (sum2 << 16));
|
||||
StringBuilder fletcherOutput = new StringBuilder();
|
||||
|
||||
for (int i = 0; i < BigEndianBitConverter.GetBytes(finalSum).Length; i++)
|
||||
for(int i = 0; i < BigEndianBitConverter.GetBytes(finalSum).Length; i++)
|
||||
{
|
||||
fletcherOutput.Append(BigEndianBitConverter.GetBytes(finalSum)[i].ToString("x2"));
|
||||
}
|
||||
@@ -193,9 +193,9 @@ namespace DiscImageChef.Checksums
|
||||
localSum2 = 0xFFFF;
|
||||
block = 0;
|
||||
|
||||
if (fileStream.Length % 2 == 0)
|
||||
if(fileStream.Length % 2 == 0)
|
||||
{
|
||||
for (int i = 0; i < fileStream.Length; i += 2)
|
||||
for(int i = 0; i < fileStream.Length; i += 2)
|
||||
{
|
||||
blockBytes = new byte[2];
|
||||
fileStream.Read(blockBytes, 0, 2);
|
||||
@@ -206,7 +206,7 @@ namespace DiscImageChef.Checksums
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < fileStream.Length - 1; i += 2)
|
||||
for(int i = 0; i < fileStream.Length - 1; i += 2)
|
||||
{
|
||||
blockBytes = new byte[2];
|
||||
fileStream.Read(blockBytes, 0, 2);
|
||||
@@ -230,7 +230,7 @@ namespace DiscImageChef.Checksums
|
||||
|
||||
StringBuilder fletcherOutput = new StringBuilder();
|
||||
|
||||
for (int i = 0; i < hash.Length; i++)
|
||||
for(int i = 0; i < hash.Length; i++)
|
||||
{
|
||||
fletcherOutput.Append(hash[i].ToString("x2"));
|
||||
}
|
||||
@@ -253,9 +253,9 @@ namespace DiscImageChef.Checksums
|
||||
localSum2 = 0xFFFF;
|
||||
block = 0;
|
||||
|
||||
if (len % 2 == 0)
|
||||
if(len % 2 == 0)
|
||||
{
|
||||
for (int i = 0; i < len; i += 2)
|
||||
for(int i = 0; i < len; i += 2)
|
||||
{
|
||||
block = BigEndianBitConverter.ToUInt16(data, i);
|
||||
localSum1 = (UInt16)((localSum1 + block) % 0xFFFF);
|
||||
@@ -264,7 +264,7 @@ namespace DiscImageChef.Checksums
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < len - 1; i += 2)
|
||||
for(int i = 0; i < len - 1; i += 2)
|
||||
{
|
||||
block = BigEndianBitConverter.ToUInt16(data, i);
|
||||
localSum1 = (UInt16)((localSum1 + block) % 0xFFFF);
|
||||
@@ -286,7 +286,7 @@ namespace DiscImageChef.Checksums
|
||||
|
||||
StringBuilder fletcherOutput = new StringBuilder();
|
||||
|
||||
for (int i = 0; i < hash.Length; i++)
|
||||
for(int i = 0; i < hash.Length; i++)
|
||||
{
|
||||
fletcherOutput.Append(hash[i].ToString("x2"));
|
||||
}
|
||||
@@ -325,7 +325,7 @@ namespace DiscImageChef.Checksums
|
||||
/// <param name="len">Length of buffer to hash.</param>
|
||||
public void Update(byte[] data, uint len)
|
||||
{
|
||||
for (int i = 0; i < len; i++)
|
||||
for(int i = 0; i < len; i++)
|
||||
{
|
||||
sum1 = (byte)((sum1 + data[i]) % 0xFF);
|
||||
sum2 = (byte)((sum2 + sum1) % 0xFF);
|
||||
@@ -358,7 +358,7 @@ namespace DiscImageChef.Checksums
|
||||
UInt16 finalSum = (UInt16)(sum1 + (sum2 << 8));
|
||||
StringBuilder fletcherOutput = new StringBuilder();
|
||||
|
||||
for (int i = 0; i < BigEndianBitConverter.GetBytes(finalSum).Length; i++)
|
||||
for(int i = 0; i < BigEndianBitConverter.GetBytes(finalSum).Length; i++)
|
||||
{
|
||||
fletcherOutput.Append(BigEndianBitConverter.GetBytes(finalSum)[i].ToString("x2"));
|
||||
}
|
||||
@@ -392,7 +392,7 @@ namespace DiscImageChef.Checksums
|
||||
localSum2 = 0xFF;
|
||||
block = 0;
|
||||
|
||||
for (int i = 0; i < fileStream.Length; i += 2)
|
||||
for(int i = 0; i < fileStream.Length; i += 2)
|
||||
{
|
||||
block = (byte)fileStream.ReadByte();
|
||||
localSum1 = (byte)((localSum1 + block) % 0xFF);
|
||||
@@ -405,7 +405,7 @@ namespace DiscImageChef.Checksums
|
||||
|
||||
StringBuilder fletcherOutput = new StringBuilder();
|
||||
|
||||
for (int i = 0; i < hash.Length; i++)
|
||||
for(int i = 0; i < hash.Length; i++)
|
||||
{
|
||||
fletcherOutput.Append(hash[i].ToString("x2"));
|
||||
}
|
||||
@@ -427,7 +427,7 @@ namespace DiscImageChef.Checksums
|
||||
localSum1 = 0xFF;
|
||||
localSum2 = 0xFF;
|
||||
|
||||
for (int i = 0; i < len; i++)
|
||||
for(int i = 0; i < len; i++)
|
||||
{
|
||||
localSum1 = (byte)((localSum1 + data[i]) % 0xFF);
|
||||
localSum2 = (byte)((localSum2 + localSum1) % 0xFF);
|
||||
@@ -439,7 +439,7 @@ namespace DiscImageChef.Checksums
|
||||
|
||||
StringBuilder fletcherOutput = new StringBuilder();
|
||||
|
||||
for (int i = 0; i < hash.Length; i++)
|
||||
for(int i = 0; i < hash.Length; i++)
|
||||
{
|
||||
fletcherOutput.Append(hash[i].ToString("x2"));
|
||||
}
|
||||
|
||||
@@ -89,10 +89,10 @@ namespace DiscImageChef.Checksums
|
||||
/// </summary>
|
||||
public string End()
|
||||
{
|
||||
_md5Provider.TransformFinalBlock(new byte[0], 0, 0);
|
||||
_md5Provider.TransformFinalBlock(new byte[0], 0, 0);
|
||||
StringBuilder md5Output = new StringBuilder();
|
||||
|
||||
for (int i = 0; i < _md5Provider.Hash.Length; i++)
|
||||
for(int i = 0; i < _md5Provider.Hash.Length; i++)
|
||||
{
|
||||
md5Output.Append(_md5Provider.Hash[i].ToString("x2"));
|
||||
}
|
||||
@@ -121,7 +121,7 @@ namespace DiscImageChef.Checksums
|
||||
hash = _md5Provider.ComputeHash(fileStream);
|
||||
StringBuilder md5Output = new StringBuilder();
|
||||
|
||||
for (int i = 0; i < hash.Length; i++)
|
||||
for(int i = 0; i < hash.Length; i++)
|
||||
{
|
||||
md5Output.Append(hash[i].ToString("x2"));
|
||||
}
|
||||
@@ -140,7 +140,7 @@ namespace DiscImageChef.Checksums
|
||||
hash = _md5Provider.ComputeHash(data, 0, (int)len);
|
||||
StringBuilder md5Output = new StringBuilder();
|
||||
|
||||
for (int i = 0; i < hash.Length; i++)
|
||||
for(int i = 0; i < hash.Length; i++)
|
||||
{
|
||||
md5Output.Append(hash[i].ToString("x2"));
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ namespace DiscImageChef.Checksums
|
||||
_ripemd160Provider.TransformFinalBlock(new byte[0], 0, 0);
|
||||
StringBuilder ripemd160Output = new StringBuilder();
|
||||
|
||||
for (int i = 0; i < _ripemd160Provider.Hash.Length; i++)
|
||||
for(int i = 0; i < _ripemd160Provider.Hash.Length; i++)
|
||||
{
|
||||
ripemd160Output.Append(_ripemd160Provider.Hash[i].ToString("x2"));
|
||||
}
|
||||
@@ -121,7 +121,7 @@ namespace DiscImageChef.Checksums
|
||||
hash = _ripemd160Provider.ComputeHash(fileStream);
|
||||
StringBuilder ripemd160Output = new StringBuilder();
|
||||
|
||||
for (int i = 0; i < hash.Length; i++)
|
||||
for(int i = 0; i < hash.Length; i++)
|
||||
{
|
||||
ripemd160Output.Append(hash[i].ToString("x2"));
|
||||
}
|
||||
@@ -140,7 +140,7 @@ namespace DiscImageChef.Checksums
|
||||
hash = _ripemd160Provider.ComputeHash(data, 0, (int)len);
|
||||
StringBuilder ripemd160Output = new StringBuilder();
|
||||
|
||||
for (int i = 0; i < hash.Length; i++)
|
||||
for(int i = 0; i < hash.Length; i++)
|
||||
{
|
||||
ripemd160Output.Append(hash[i].ToString("x2"));
|
||||
}
|
||||
|
||||
174
ReedSolomon.cs
174
ReedSolomon.cs
@@ -97,52 +97,52 @@ namespace DiscImageChef.Checksums
|
||||
/// </summary>
|
||||
public void InitRS(int n, int k, int m)
|
||||
{
|
||||
switch (m)
|
||||
switch(m)
|
||||
{
|
||||
case 2:
|
||||
Pp = new []{ 1, 1, 1 };
|
||||
Pp = new[] { 1, 1, 1 };
|
||||
break;
|
||||
case 3:
|
||||
Pp = new []{ 1, 1, 0, 1 };
|
||||
Pp = new[] { 1, 1, 0, 1 };
|
||||
break;
|
||||
case 4:
|
||||
Pp = new []{ 1, 1, 0, 0, 1 };
|
||||
Pp = new[] { 1, 1, 0, 0, 1 };
|
||||
break;
|
||||
case 5:
|
||||
Pp = new []{ 1, 0, 1, 0, 0, 1 };
|
||||
Pp = new[] { 1, 0, 1, 0, 0, 1 };
|
||||
break;
|
||||
case 6:
|
||||
Pp = new []{ 1, 1, 0, 0, 0, 0, 1 };
|
||||
Pp = new[] { 1, 1, 0, 0, 0, 0, 1 };
|
||||
break;
|
||||
case 7:
|
||||
Pp = new []{ 1, 0, 0, 1, 0, 0, 0, 1 };
|
||||
Pp = new[] { 1, 0, 0, 1, 0, 0, 0, 1 };
|
||||
break;
|
||||
case 8:
|
||||
Pp = new []{ 1, 0, 1, 1, 1, 0, 0, 0, 1 };
|
||||
Pp = new[] { 1, 0, 1, 1, 1, 0, 0, 0, 1 };
|
||||
break;
|
||||
case 9:
|
||||
Pp = new []{ 1, 0, 0, 0, 1, 0, 0, 0, 0, 1 };
|
||||
Pp = new[] { 1, 0, 0, 0, 1, 0, 0, 0, 0, 1 };
|
||||
break;
|
||||
case 10:
|
||||
Pp = new []{ 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1 };
|
||||
Pp = new[] { 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1 };
|
||||
break;
|
||||
case 11:
|
||||
Pp = new []{ 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1 };
|
||||
Pp = new[] { 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1 };
|
||||
break;
|
||||
case 12:
|
||||
Pp = new []{ 1, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1 };
|
||||
Pp = new[] { 1, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1 };
|
||||
break;
|
||||
case 13:
|
||||
Pp = new []{ 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1 };
|
||||
Pp = new[] { 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1 };
|
||||
break;
|
||||
case 14:
|
||||
Pp = new []{ 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1 };
|
||||
Pp = new[] { 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1 };
|
||||
break;
|
||||
case 15:
|
||||
Pp = new []{ 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 };
|
||||
Pp = new[] { 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 };
|
||||
break;
|
||||
case 16:
|
||||
Pp = new []{ 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1 };
|
||||
Pp = new[] { 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1 };
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException("m", "m must be between 2 and 16 inclusive");
|
||||
@@ -166,7 +166,7 @@ namespace DiscImageChef.Checksums
|
||||
|
||||
int modnn(int x)
|
||||
{
|
||||
while (x >= NN)
|
||||
while(x >= NN)
|
||||
{
|
||||
x -= NN;
|
||||
x = (x >> MM) + (x & NN);
|
||||
@@ -182,21 +182,21 @@ namespace DiscImageChef.Checksums
|
||||
static void CLEAR(ref int[] a, int n)
|
||||
{
|
||||
int ci;
|
||||
for (ci = (n) - 1; ci >= 0; ci--)
|
||||
for(ci = (n) - 1; ci >= 0; ci--)
|
||||
(a)[ci] = 0;
|
||||
}
|
||||
|
||||
static void COPY(ref int[] a, ref int[] b, int n)
|
||||
{
|
||||
int ci;
|
||||
for (ci = (n) - 1; ci >= 0; ci--)
|
||||
for(ci = (n) - 1; ci >= 0; ci--)
|
||||
(a)[ci] = (b)[ci];
|
||||
}
|
||||
|
||||
static void COPYDOWN(ref int[] a, ref int[] b, int n)
|
||||
{
|
||||
int ci;
|
||||
for (ci = (n) - 1; ci >= 0; ci--)
|
||||
for(ci = (n) - 1; ci >= 0; ci--)
|
||||
(a)[ci] = (b)[ci];
|
||||
}
|
||||
|
||||
@@ -236,12 +236,12 @@ namespace DiscImageChef.Checksums
|
||||
|
||||
mask = 1;
|
||||
Alpha_to[MM] = 0;
|
||||
for (i = 0; i < MM; i++)
|
||||
for(i = 0; i < MM; i++)
|
||||
{
|
||||
Alpha_to[i] = mask;
|
||||
Index_of[Alpha_to[i]] = i;
|
||||
/* If Pp[i] == 1 then, term @^i occurs in poly-repr of @^MM */
|
||||
if (Pp[i] != 0)
|
||||
if(Pp[i] != 0)
|
||||
Alpha_to[MM] ^= mask; /* Bit-wise EXOR operation */
|
||||
mask <<= 1; /* single left-shift */
|
||||
}
|
||||
@@ -252,9 +252,9 @@ namespace DiscImageChef.Checksums
|
||||
* term that may occur when poly-repr of @^i is shifted.
|
||||
*/
|
||||
mask >>= 1;
|
||||
for (i = MM + 1; i < NN; i++)
|
||||
for(i = MM + 1; i < NN; i++)
|
||||
{
|
||||
if (Alpha_to[i - 1] >= mask)
|
||||
if(Alpha_to[i - 1] >= mask)
|
||||
Alpha_to[i] = Alpha_to[MM] ^ ((Alpha_to[i - 1] ^ mask) << 1);
|
||||
else
|
||||
Alpha_to[i] = Alpha_to[i - 1] << 1;
|
||||
@@ -283,15 +283,15 @@ namespace DiscImageChef.Checksums
|
||||
|
||||
Gg[0] = Alpha_to[B0];
|
||||
Gg[1] = 1; /* g(x) = (X+@**B0) initially */
|
||||
for (i = 2; i <= NN - KK; i++)
|
||||
for(i = 2; i <= NN - KK; i++)
|
||||
{
|
||||
Gg[i] = 1;
|
||||
/*
|
||||
* Below multiply (Gg[0]+Gg[1]*x + ... +Gg[i]x^i) by
|
||||
* (@**(B0+i-1) + x)
|
||||
*/
|
||||
for (j = i - 1; j > 0; j--)
|
||||
if (Gg[j] != 0)
|
||||
for(j = i - 1; j > 0; j--)
|
||||
if(Gg[j] != 0)
|
||||
Gg[j] = Gg[j - 1] ^ Alpha_to[modnn((Index_of[Gg[j]]) + B0 + i - 1)];
|
||||
else
|
||||
Gg[j] = Gg[j - 1];
|
||||
@@ -299,7 +299,7 @@ namespace DiscImageChef.Checksums
|
||||
Gg[0] = Alpha_to[modnn((Index_of[Gg[0]]) + B0 + i - 1)];
|
||||
}
|
||||
/* convert Gg[] to index form for quicker encoding */
|
||||
for (i = 0; i <= NN - KK; i++)
|
||||
for(i = 0; i <= NN - KK; i++)
|
||||
Gg[i] = Index_of[Gg[i]];
|
||||
}
|
||||
|
||||
@@ -319,25 +319,25 @@ namespace DiscImageChef.Checksums
|
||||
/// <param name="bb">Outs parity symbols.</param>
|
||||
public int encode_rs(int[] data, out int[] bb)
|
||||
{
|
||||
if (initialized)
|
||||
if(initialized)
|
||||
{
|
||||
int i, j;
|
||||
int feedback;
|
||||
bb = new int[NN - KK];
|
||||
|
||||
CLEAR(ref bb, NN - KK);
|
||||
for (i = KK - 1; i >= 0; i--)
|
||||
for(i = KK - 1; i >= 0; i--)
|
||||
{
|
||||
if (MM != 8)
|
||||
if(MM != 8)
|
||||
{
|
||||
if (data[i] > NN)
|
||||
if(data[i] > NN)
|
||||
return -1; /* Illegal symbol */
|
||||
}
|
||||
feedback = Index_of[data[i] ^ bb[NN - KK - 1]];
|
||||
if (feedback != A0)
|
||||
if(feedback != A0)
|
||||
{ /* feedback term is non-zero */
|
||||
for (j = NN - KK - 1; j > 0; j--)
|
||||
if (Gg[j] != A0)
|
||||
for(j = NN - KK - 1; j > 0; j--)
|
||||
if(Gg[j] != A0)
|
||||
bb[j] = bb[j - 1] ^ Alpha_to[modnn(Gg[j] + feedback)];
|
||||
else
|
||||
bb[j] = bb[j - 1];
|
||||
@@ -346,7 +346,7 @@ namespace DiscImageChef.Checksums
|
||||
else
|
||||
{ /* feedback term is zero. encoder becomes a
|
||||
* single-byte shifter */
|
||||
for (j = NN - KK - 1; j > 0; j--)
|
||||
for(j = NN - KK - 1; j > 0; j--)
|
||||
bb[j] = bb[j - 1];
|
||||
bb[0] = 0;
|
||||
}
|
||||
@@ -378,7 +378,7 @@ namespace DiscImageChef.Checksums
|
||||
/// <param name="no_eras">Number of erasures.</param>
|
||||
public int eras_dec_rs(ref int[] data, out int[] eras_pos, int no_eras)
|
||||
{
|
||||
if (initialized)
|
||||
if(initialized)
|
||||
{
|
||||
eras_pos = new int[NN - KK];
|
||||
int deg_lambda, el, deg_omega;
|
||||
@@ -396,11 +396,11 @@ namespace DiscImageChef.Checksums
|
||||
int syn_error, count;
|
||||
|
||||
/* data[] is in polynomial form, copy and convert to index form */
|
||||
for (i = NN - 1; i >= 0; i--)
|
||||
for(i = NN - 1; i >= 0; i--)
|
||||
{
|
||||
if (MM != 8)
|
||||
if(MM != 8)
|
||||
{
|
||||
if (data[i] > NN)
|
||||
if(data[i] > NN)
|
||||
return -1; /* Illegal symbol */
|
||||
}
|
||||
recd[i] = Index_of[data[i]];
|
||||
@@ -409,18 +409,18 @@ namespace DiscImageChef.Checksums
|
||||
* namely @**(B0+i), i = 0, ... ,(NN-KK-1)
|
||||
*/
|
||||
syn_error = 0;
|
||||
for (i = 1; i <= NN - KK; i++)
|
||||
for(i = 1; i <= NN - KK; i++)
|
||||
{
|
||||
tmp = 0;
|
||||
for (j = 0; j < NN; j++)
|
||||
if (recd[j] != A0) /* recd[j] in index form */
|
||||
for(j = 0; j < NN; j++)
|
||||
if(recd[j] != A0) /* recd[j] in index form */
|
||||
tmp ^= Alpha_to[modnn(recd[j] + (B0 + i - 1) * j)];
|
||||
syn_error |= tmp; /* set flag if non-zero syndrome =>
|
||||
* error */
|
||||
/* store syndrome in index form */
|
||||
s[i] = Index_of[tmp];
|
||||
}
|
||||
if (syn_error == 0)
|
||||
if(syn_error == 0)
|
||||
{
|
||||
/*
|
||||
* if syndrome is zero, data[] is a codeword and there are no
|
||||
@@ -430,36 +430,36 @@ namespace DiscImageChef.Checksums
|
||||
}
|
||||
CLEAR(ref lambda, NN - KK);
|
||||
lambda[0] = 1;
|
||||
if (no_eras > 0)
|
||||
if(no_eras > 0)
|
||||
{
|
||||
/* Init lambda to be the erasure locator polynomial */
|
||||
lambda[1] = Alpha_to[eras_pos[0]];
|
||||
for (i = 1; i < no_eras; i++)
|
||||
for(i = 1; i < no_eras; i++)
|
||||
{
|
||||
u = eras_pos[i];
|
||||
for (j = i + 1; j > 0; j--)
|
||||
for(j = i + 1; j > 0; j--)
|
||||
{
|
||||
tmp = Index_of[lambda[j - 1]];
|
||||
if (tmp != A0)
|
||||
if(tmp != A0)
|
||||
lambda[j] ^= Alpha_to[modnn(u + tmp)];
|
||||
}
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
#if DEBUG
|
||||
/* find roots of the erasure location polynomial */
|
||||
for (i = 1; i <= no_eras; i++)
|
||||
for(i = 1; i <= no_eras; i++)
|
||||
reg[i] = Index_of[lambda[i]];
|
||||
count = 0;
|
||||
for (i = 1; i <= NN; i++)
|
||||
for(i = 1; i <= NN; i++)
|
||||
{
|
||||
q = 1;
|
||||
for (j = 1; j <= no_eras; j++)
|
||||
if (reg[j] != A0)
|
||||
for(j = 1; j <= no_eras; j++)
|
||||
if(reg[j] != A0)
|
||||
{
|
||||
reg[j] = modnn(reg[j] + j);
|
||||
q ^= Alpha_to[reg[j]];
|
||||
}
|
||||
if (q == 0)
|
||||
if(q == 0)
|
||||
{
|
||||
/* store root and error location
|
||||
* number indices
|
||||
@@ -469,19 +469,19 @@ namespace DiscImageChef.Checksums
|
||||
count++;
|
||||
}
|
||||
}
|
||||
if (count != no_eras)
|
||||
if(count != no_eras)
|
||||
{
|
||||
DicConsole.DebugWriteLine("Reed Solomon", "\n lambda(x) is WRONG\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
DicConsole.DebugWriteLine("Reed Solomon", "\n Erasure positions as determined by roots of Eras Loc Poly:\n");
|
||||
for (i = 0; i < count; i++)
|
||||
for(i = 0; i < count; i++)
|
||||
DicConsole.DebugWriteLine("Reed Solomon", "{0} ", loc[i]);
|
||||
DicConsole.DebugWriteLine("Reed Solomon", "\n");
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
for (i = 0; i < NN - KK + 1; i++)
|
||||
for(i = 0; i < NN - KK + 1; i++)
|
||||
b[i] = Index_of[lambda[i]];
|
||||
|
||||
/*
|
||||
@@ -490,19 +490,19 @@ namespace DiscImageChef.Checksums
|
||||
*/
|
||||
r = no_eras;
|
||||
el = no_eras;
|
||||
while (++r <= NN - KK)
|
||||
while(++r <= NN - KK)
|
||||
{ /* r is the step number */
|
||||
/* Compute discrepancy at the r-th step in poly-form */
|
||||
discr_r = 0;
|
||||
for (i = 0; i < r; i++)
|
||||
for(i = 0; i < r; i++)
|
||||
{
|
||||
if ((lambda[i] != 0) && (s[r - i] != A0))
|
||||
if((lambda[i] != 0) && (s[r - i] != A0))
|
||||
{
|
||||
discr_r ^= Alpha_to[modnn(Index_of[lambda[i]] + s[r - i])];
|
||||
}
|
||||
}
|
||||
discr_r = Index_of[discr_r]; /* Index form */
|
||||
if (discr_r == A0)
|
||||
if(discr_r == A0)
|
||||
{
|
||||
/* 2 lines below: B(x) <-- x*B(x) */
|
||||
COPYDOWN(ref b, ref b, NN - KK);
|
||||
@@ -512,21 +512,21 @@ namespace DiscImageChef.Checksums
|
||||
{
|
||||
/* 7 lines below: T(x) <-- lambda(x) - discr_r*x*b(x) */
|
||||
t[0] = lambda[0];
|
||||
for (i = 0; i < NN - KK; i++)
|
||||
for(i = 0; i < NN - KK; i++)
|
||||
{
|
||||
if (b[i] != A0)
|
||||
if(b[i] != A0)
|
||||
t[i + 1] = lambda[i + 1] ^ Alpha_to[modnn(discr_r + b[i])];
|
||||
else
|
||||
t[i + 1] = lambda[i + 1];
|
||||
}
|
||||
if (2 * el <= r + no_eras - 1)
|
||||
if(2 * el <= r + no_eras - 1)
|
||||
{
|
||||
el = r + no_eras - el;
|
||||
/*
|
||||
* 2 lines below: B(x) <-- inv(discr_r) *
|
||||
* lambda(x)
|
||||
*/
|
||||
for (i = 0; i <= NN - KK; i++)
|
||||
for(i = 0; i <= NN - KK; i++)
|
||||
b[i] = (lambda[i] == 0) ? A0 : modnn(Index_of[lambda[i]] - discr_r + NN);
|
||||
}
|
||||
else
|
||||
@@ -541,10 +541,10 @@ namespace DiscImageChef.Checksums
|
||||
|
||||
/* Convert lambda to index form and compute deg(lambda(x)) */
|
||||
deg_lambda = 0;
|
||||
for (i = 0; i < NN - KK + 1; i++)
|
||||
for(i = 0; i < NN - KK + 1; i++)
|
||||
{
|
||||
lambda[i] = Index_of[lambda[i]];
|
||||
if (lambda[i] != A0)
|
||||
if(lambda[i] != A0)
|
||||
deg_lambda = i;
|
||||
}
|
||||
/*
|
||||
@@ -555,16 +555,16 @@ namespace DiscImageChef.Checksums
|
||||
COPY(ref reg, ref lambda, NN - KK);
|
||||
reg[0] = temp;
|
||||
count = 0; /* Number of roots of lambda(x) */
|
||||
for (i = 1; i <= NN; i++)
|
||||
for(i = 1; i <= NN; i++)
|
||||
{
|
||||
q = 1;
|
||||
for (j = deg_lambda; j > 0; j--)
|
||||
if (reg[j] != A0)
|
||||
for(j = deg_lambda; j > 0; j--)
|
||||
if(reg[j] != A0)
|
||||
{
|
||||
reg[j] = modnn(reg[j] + j);
|
||||
q ^= Alpha_to[reg[j]];
|
||||
}
|
||||
if (q == 0)
|
||||
if(q == 0)
|
||||
{
|
||||
/* store root (index-form) and error location number */
|
||||
root[count] = i;
|
||||
@@ -573,14 +573,14 @@ namespace DiscImageChef.Checksums
|
||||
}
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
#if DEBUG
|
||||
DicConsole.DebugWriteLine("Reed Solomon", "\n Final error positions:\t");
|
||||
for (i = 0; i < count; i++)
|
||||
for(i = 0; i < count; i++)
|
||||
DicConsole.DebugWriteLine("Reed Solomon", "{0} ", loc[i]);
|
||||
DicConsole.DebugWriteLine("Reed Solomon", "\n");
|
||||
#endif
|
||||
#endif
|
||||
|
||||
if (deg_lambda != count)
|
||||
if(deg_lambda != count)
|
||||
{
|
||||
/*
|
||||
* deg(lambda) unequal to number of roots => uncorrectable
|
||||
@@ -593,16 +593,16 @@ namespace DiscImageChef.Checksums
|
||||
* x**(NN-KK)). in index form. Also find deg(omega).
|
||||
*/
|
||||
deg_omega = 0;
|
||||
for (i = 0; i < NN - KK; i++)
|
||||
for(i = 0; i < NN - KK; i++)
|
||||
{
|
||||
tmp = 0;
|
||||
j = (deg_lambda < i) ? deg_lambda : i;
|
||||
for (; j >= 0; j--)
|
||||
for(; j >= 0; j--)
|
||||
{
|
||||
if ((s[i + 1 - j] != A0) && (lambda[j] != A0))
|
||||
if((s[i + 1 - j] != A0) && (lambda[j] != A0))
|
||||
tmp ^= Alpha_to[modnn(s[i + 1 - j] + lambda[j])];
|
||||
}
|
||||
if (tmp != 0)
|
||||
if(tmp != 0)
|
||||
deg_omega = i;
|
||||
omega[i] = Index_of[tmp];
|
||||
}
|
||||
@@ -612,30 +612,30 @@ namespace DiscImageChef.Checksums
|
||||
* Compute error values in poly-form. num1 = omega(inv(X(l))), num2 =
|
||||
* inv(X(l))**(B0-1) and den = lambda_pr(inv(X(l))) all in poly-form
|
||||
*/
|
||||
for (j = count - 1; j >= 0; j--)
|
||||
for(j = count - 1; j >= 0; j--)
|
||||
{
|
||||
num1 = 0;
|
||||
for (i = deg_omega; i >= 0; i--)
|
||||
for(i = deg_omega; i >= 0; i--)
|
||||
{
|
||||
if (omega[i] != A0)
|
||||
if(omega[i] != A0)
|
||||
num1 ^= Alpha_to[modnn(omega[i] + i * root[j])];
|
||||
}
|
||||
num2 = Alpha_to[modnn(root[j] * (B0 - 1) + NN)];
|
||||
den = 0;
|
||||
|
||||
/* lambda[i+1] for i even is the formal derivative lambda_pr of lambda[i] */
|
||||
for (i = min(deg_lambda, NN - KK - 1) & ~1; i >= 0; i -= 2)
|
||||
for(i = min(deg_lambda, NN - KK - 1) & ~1; i >= 0; i -= 2)
|
||||
{
|
||||
if (lambda[i + 1] != A0)
|
||||
if(lambda[i + 1] != A0)
|
||||
den ^= Alpha_to[modnn(lambda[i + 1] + i * root[j])];
|
||||
}
|
||||
if (den == 0)
|
||||
if(den == 0)
|
||||
{
|
||||
DicConsole.DebugWriteLine("Reed Solomon", "\n ERROR: denominator = 0\n");
|
||||
return -1;
|
||||
}
|
||||
/* Apply error to data */
|
||||
if (num1 != 0)
|
||||
if(num1 != 0)
|
||||
{
|
||||
data[loc[j]] ^= Alpha_to[modnn(Index_of[num1] + Index_of[num2] + NN - Index_of[den])];
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ namespace DiscImageChef.Checksums
|
||||
_sha1Provider.TransformFinalBlock(new byte[0], 0, 0);
|
||||
StringBuilder sha1Output = new StringBuilder();
|
||||
|
||||
for (int i = 0; i < _sha1Provider.Hash.Length; i++)
|
||||
for(int i = 0; i < _sha1Provider.Hash.Length; i++)
|
||||
{
|
||||
sha1Output.Append(_sha1Provider.Hash[i].ToString("x2"));
|
||||
}
|
||||
@@ -121,7 +121,7 @@ namespace DiscImageChef.Checksums
|
||||
hash = _sha1Provider.ComputeHash(fileStream);
|
||||
StringBuilder sha1Output = new StringBuilder();
|
||||
|
||||
for (int i = 0; i < hash.Length; i++)
|
||||
for(int i = 0; i < hash.Length; i++)
|
||||
{
|
||||
sha1Output.Append(hash[i].ToString("x2"));
|
||||
}
|
||||
@@ -140,7 +140,7 @@ namespace DiscImageChef.Checksums
|
||||
hash = _sha1Provider.ComputeHash(data, 0, (int)len);
|
||||
StringBuilder sha1Output = new StringBuilder();
|
||||
|
||||
for (int i = 0; i < hash.Length; i++)
|
||||
for(int i = 0; i < hash.Length; i++)
|
||||
{
|
||||
sha1Output.Append(hash[i].ToString("x2"));
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ namespace DiscImageChef.Checksums
|
||||
_sha256Provider.TransformFinalBlock(new byte[0], 0, 0);
|
||||
StringBuilder sha256Output = new StringBuilder();
|
||||
|
||||
for (int i = 0; i < _sha256Provider.Hash.Length; i++)
|
||||
for(int i = 0; i < _sha256Provider.Hash.Length; i++)
|
||||
{
|
||||
sha256Output.Append(_sha256Provider.Hash[i].ToString("x2"));
|
||||
}
|
||||
@@ -121,7 +121,7 @@ namespace DiscImageChef.Checksums
|
||||
hash = _sha256Provider.ComputeHash(fileStream);
|
||||
StringBuilder sha256Output = new StringBuilder();
|
||||
|
||||
for (int i = 0; i < hash.Length; i++)
|
||||
for(int i = 0; i < hash.Length; i++)
|
||||
{
|
||||
sha256Output.Append(hash[i].ToString("x2"));
|
||||
}
|
||||
@@ -140,7 +140,7 @@ namespace DiscImageChef.Checksums
|
||||
hash = _sha256Provider.ComputeHash(data, 0, (int)len);
|
||||
StringBuilder sha256Output = new StringBuilder();
|
||||
|
||||
for (int i = 0; i < hash.Length; i++)
|
||||
for(int i = 0; i < hash.Length; i++)
|
||||
{
|
||||
sha256Output.Append(hash[i].ToString("x2"));
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ namespace DiscImageChef.Checksums
|
||||
_sha384Provider.TransformFinalBlock(new byte[0], 0, 0);
|
||||
StringBuilder sha384Output = new StringBuilder();
|
||||
|
||||
for (int i = 0; i < _sha384Provider.Hash.Length; i++)
|
||||
for(int i = 0; i < _sha384Provider.Hash.Length; i++)
|
||||
{
|
||||
sha384Output.Append(_sha384Provider.Hash[i].ToString("x2"));
|
||||
}
|
||||
@@ -121,7 +121,7 @@ namespace DiscImageChef.Checksums
|
||||
hash = _sha384Provider.ComputeHash(fileStream);
|
||||
StringBuilder sha384Output = new StringBuilder();
|
||||
|
||||
for (int i = 0; i < hash.Length; i++)
|
||||
for(int i = 0; i < hash.Length; i++)
|
||||
{
|
||||
sha384Output.Append(hash[i].ToString("x2"));
|
||||
}
|
||||
@@ -140,7 +140,7 @@ namespace DiscImageChef.Checksums
|
||||
hash = _sha384Provider.ComputeHash(data, 0, (int)len);
|
||||
StringBuilder sha384Output = new StringBuilder();
|
||||
|
||||
for (int i = 0; i < hash.Length; i++)
|
||||
for(int i = 0; i < hash.Length; i++)
|
||||
{
|
||||
sha384Output.Append(hash[i].ToString("x2"));
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ namespace DiscImageChef.Checksums
|
||||
_sha512Provider.TransformFinalBlock(new byte[0], 0, 0);
|
||||
StringBuilder sha512Output = new StringBuilder();
|
||||
|
||||
for (int i = 0; i < _sha512Provider.Hash.Length; i++)
|
||||
for(int i = 0; i < _sha512Provider.Hash.Length; i++)
|
||||
{
|
||||
sha512Output.Append(_sha512Provider.Hash[i].ToString("x2"));
|
||||
}
|
||||
@@ -121,7 +121,7 @@ namespace DiscImageChef.Checksums
|
||||
hash = _sha512Provider.ComputeHash(fileStream);
|
||||
StringBuilder sha512Output = new StringBuilder();
|
||||
|
||||
for (int i = 0; i < hash.Length; i++)
|
||||
for(int i = 0; i < hash.Length; i++)
|
||||
{
|
||||
sha512Output.Append(hash[i].ToString("x2"));
|
||||
}
|
||||
@@ -140,7 +140,7 @@ namespace DiscImageChef.Checksums
|
||||
hash = _sha512Provider.ComputeHash(data, 0, (int)len);
|
||||
StringBuilder sha512Output = new StringBuilder();
|
||||
|
||||
for (int i = 0; i < hash.Length; i++)
|
||||
for(int i = 0; i < hash.Length; i++)
|
||||
{
|
||||
sha512Output.Append(hash[i].ToString("x2"));
|
||||
}
|
||||
|
||||
@@ -122,7 +122,7 @@ namespace DiscImageChef.Checksums
|
||||
{
|
||||
self = new fuzzy_state();
|
||||
self.bh = new blockhash_context[NUM_BLOCKHASHES];
|
||||
for (int i = 0; i < NUM_BLOCKHASHES; i++)
|
||||
for(int i = 0; i < NUM_BLOCKHASHES; i++)
|
||||
self.bh[i].digest = new byte[SPAMSUM_LENGTH];
|
||||
|
||||
self.bhstart = 0;
|
||||
@@ -184,10 +184,10 @@ namespace DiscImageChef.Checksums
|
||||
{
|
||||
uint obh, nbh;
|
||||
|
||||
if (self.bhend >= NUM_BLOCKHASHES)
|
||||
if(self.bhend >= NUM_BLOCKHASHES)
|
||||
return;
|
||||
|
||||
if (self.bhend == 0) // assert
|
||||
if(self.bhend == 0) // assert
|
||||
throw new Exception("Assertion failed");
|
||||
|
||||
obh = self.bhend - 1;
|
||||
@@ -202,18 +202,18 @@ namespace DiscImageChef.Checksums
|
||||
|
||||
void fuzzy_try_reduce_blockhash()
|
||||
{
|
||||
if (self.bhstart >= self.bhend)
|
||||
if(self.bhstart >= self.bhend)
|
||||
throw new Exception("Assertion failed");
|
||||
|
||||
if (self.bhend - self.bhstart < 2)
|
||||
if(self.bhend - self.bhstart < 2)
|
||||
/* Need at least two working hashes. */
|
||||
return;
|
||||
if ((UInt64)SSDEEP_BS(self.bhstart) * SPAMSUM_LENGTH >=
|
||||
if((UInt64)SSDEEP_BS(self.bhstart) * SPAMSUM_LENGTH >=
|
||||
self.total_size)
|
||||
/* Initial blocksize estimate would select this or a smaller
|
||||
* blocksize. */
|
||||
return;
|
||||
if (self.bh[self.bhstart + 1].dlen < SPAMSUM_LENGTH / 2)
|
||||
if(self.bh[self.bhstart + 1].dlen < SPAMSUM_LENGTH / 2)
|
||||
/* Estimate adjustment would select this blocksize. */
|
||||
return;
|
||||
/* At this point we are clearly no longer interested in the
|
||||
@@ -231,16 +231,16 @@ namespace DiscImageChef.Checksums
|
||||
roll_hash(c);
|
||||
h = roll_sum();
|
||||
|
||||
for (i = self.bhstart; i < self.bhend; ++i)
|
||||
for(i = self.bhstart; i < self.bhend; ++i)
|
||||
{
|
||||
self.bh[i].h = sum_hash(c, self.bh[i].h);
|
||||
self.bh[i].halfh = sum_hash(c, self.bh[i].halfh);
|
||||
}
|
||||
|
||||
for (i = self.bhstart; i < self.bhend; ++i)
|
||||
for(i = self.bhstart; i < self.bhend; ++i)
|
||||
{
|
||||
/* With growing blocksize almost no runs fail the next test. */
|
||||
if (h % SSDEEP_BS(i) != SSDEEP_BS(i) - 1)
|
||||
if(h % SSDEEP_BS(i) != SSDEEP_BS(i) - 1)
|
||||
/* Once this condition is false for one bs, it is
|
||||
* automatically false for all further bs. I.e. if
|
||||
* h === -1 (mod 2*bs) then h === -1 (mod bs). */
|
||||
@@ -248,7 +248,7 @@ namespace DiscImageChef.Checksums
|
||||
/* We have hit a reset point. We now emit hashes which are
|
||||
* based on all characters in the piece of the message between
|
||||
* the last reset point and this one */
|
||||
if (0 == self.bh[i].dlen)
|
||||
if(0 == self.bh[i].dlen)
|
||||
{
|
||||
/* Can only happen 30 times. */
|
||||
/* First step for this blocksize. Clone next. */
|
||||
@@ -256,7 +256,7 @@ namespace DiscImageChef.Checksums
|
||||
}
|
||||
self.bh[i].digest[self.bh[i].dlen] = b64[self.bh[i].h % 64];
|
||||
self.bh[i].halfdigest = b64[self.bh[i].halfh % 64];
|
||||
if (self.bh[i].dlen < SPAMSUM_LENGTH - 1)
|
||||
if(self.bh[i].dlen < SPAMSUM_LENGTH - 1)
|
||||
{
|
||||
/* We can have a problem with the tail overflowing. The
|
||||
* easiest way to cope with this is to only reset the
|
||||
@@ -266,7 +266,7 @@ namespace DiscImageChef.Checksums
|
||||
* */
|
||||
self.bh[i].digest[++(self.bh[i].dlen)] = 0;
|
||||
self.bh[i].h = HASH_INIT;
|
||||
if (self.bh[i].dlen < SPAMSUM_LENGTH / 2)
|
||||
if(self.bh[i].dlen < SPAMSUM_LENGTH / 2)
|
||||
{
|
||||
self.bh[i].halfh = HASH_INIT;
|
||||
self.bh[i].halfdigest = 0;
|
||||
@@ -285,7 +285,7 @@ namespace DiscImageChef.Checksums
|
||||
public void Update(byte[] data, uint len)
|
||||
{
|
||||
self.total_size += len;
|
||||
for (int i = 0; i < len; i++)
|
||||
for(int i = 0; i < len; i++)
|
||||
fuzzy_engine_step(data[i]);
|
||||
}
|
||||
|
||||
@@ -308,34 +308,34 @@ namespace DiscImageChef.Checksums
|
||||
int remain = (int)(FUZZY_MAX_RESULT - 1); /* Exclude terminating '\0'. */
|
||||
result = new byte[FUZZY_MAX_RESULT];
|
||||
/* Verify that our elimination was not overeager. */
|
||||
if (!(bi == 0 || (UInt64)SSDEEP_BS(bi) / 2 * SPAMSUM_LENGTH < self.total_size))
|
||||
if(!(bi == 0 || (UInt64)SSDEEP_BS(bi) / 2 * SPAMSUM_LENGTH < self.total_size))
|
||||
throw new Exception("Assertion failed");
|
||||
|
||||
result_off = 0;
|
||||
|
||||
/* Initial blocksize guess. */
|
||||
while ((UInt64)SSDEEP_BS(bi) * SPAMSUM_LENGTH < self.total_size)
|
||||
while((UInt64)SSDEEP_BS(bi) * SPAMSUM_LENGTH < self.total_size)
|
||||
{
|
||||
++bi;
|
||||
if (bi >= NUM_BLOCKHASHES)
|
||||
if(bi >= NUM_BLOCKHASHES)
|
||||
{
|
||||
throw new OverflowException("The input exceeds data types.");
|
||||
}
|
||||
}
|
||||
/* Adapt blocksize guess to actual digest length. */
|
||||
while (bi >= self.bhend)
|
||||
while(bi >= self.bhend)
|
||||
--bi;
|
||||
while (bi > self.bhstart && self.bh[bi].dlen < SPAMSUM_LENGTH / 2)
|
||||
while(bi > self.bhstart && self.bh[bi].dlen < SPAMSUM_LENGTH / 2)
|
||||
--bi;
|
||||
if ((bi > 0 && self.bh[bi].dlen < SPAMSUM_LENGTH / 2))
|
||||
if((bi > 0 && self.bh[bi].dlen < SPAMSUM_LENGTH / 2))
|
||||
throw new Exception("Assertion failed");
|
||||
|
||||
sb.AppendFormat("{0}:", SSDEEP_BS(bi));
|
||||
i = Encoding.ASCII.GetBytes(sb.ToString()).Length;
|
||||
if (i <= 0)
|
||||
if(i <= 0)
|
||||
/* Maybe snprintf has set errno here? */
|
||||
throw new OverflowException("The input exceeds data types.");
|
||||
if (i >= remain)
|
||||
if(i >= remain)
|
||||
throw new Exception("Assertion failed");
|
||||
remain -= i;
|
||||
|
||||
@@ -344,18 +344,18 @@ namespace DiscImageChef.Checksums
|
||||
result_off += i;
|
||||
|
||||
i = (int)self.bh[bi].dlen;
|
||||
if (i > remain)
|
||||
if(i > remain)
|
||||
throw new Exception("Assertion failed");
|
||||
|
||||
Array.Copy(self.bh[bi].digest, 0, result, result_off, i);
|
||||
result_off += i;
|
||||
remain -= i;
|
||||
if (h != 0)
|
||||
if(h != 0)
|
||||
{
|
||||
if (remain <= 0)
|
||||
if(remain <= 0)
|
||||
throw new Exception("Assertion failed");
|
||||
result[result_off] = b64[self.bh[bi].h % 64];
|
||||
if (i < 3 ||
|
||||
if(i < 3 ||
|
||||
result[result_off] != result[result_off - 1] ||
|
||||
result[result_off] != result[result_off - 2] ||
|
||||
result[result_off] != result[result_off - 3])
|
||||
@@ -364,12 +364,12 @@ namespace DiscImageChef.Checksums
|
||||
--remain;
|
||||
}
|
||||
}
|
||||
else if (self.bh[bi].digest[i] != 0)
|
||||
else if(self.bh[bi].digest[i] != 0)
|
||||
{
|
||||
if (remain <= 0)
|
||||
if(remain <= 0)
|
||||
throw new Exception("Assertion failed");
|
||||
result[result_off] = self.bh[bi].digest[i];
|
||||
if (i < 3 ||
|
||||
if(i < 3 ||
|
||||
result[result_off] != result[result_off - 1] ||
|
||||
result[result_off] != result[result_off - 2] ||
|
||||
result[result_off] != result[result_off - 3])
|
||||
@@ -378,27 +378,27 @@ namespace DiscImageChef.Checksums
|
||||
--remain;
|
||||
}
|
||||
}
|
||||
if (remain <= 0)
|
||||
if(remain <= 0)
|
||||
throw new Exception("Assertion failed");
|
||||
result[result_off++] = 0x3A; // ':'
|
||||
--remain;
|
||||
if (bi < self.bhend - 1)
|
||||
if(bi < self.bhend - 1)
|
||||
{
|
||||
++bi;
|
||||
i = (int)self.bh[bi].dlen;
|
||||
if (i > remain)
|
||||
if(i > remain)
|
||||
throw new Exception("Assertion failed");
|
||||
Array.Copy(self.bh[bi].digest, 0, result, result_off, i);
|
||||
result_off += i;
|
||||
remain -= i;
|
||||
|
||||
if (h != 0)
|
||||
if(h != 0)
|
||||
{
|
||||
if (remain <= 0)
|
||||
if(remain <= 0)
|
||||
throw new Exception("Assertion failed");
|
||||
h = self.bh[bi].halfh;
|
||||
result[result_off] = b64[h % 64];
|
||||
if (i < 3 ||
|
||||
if(i < 3 ||
|
||||
result[result_off] != result[result_off - 1] ||
|
||||
result[result_off] != result[result_off - 2] ||
|
||||
result[result_off] != result[result_off - 3])
|
||||
@@ -410,12 +410,12 @@ namespace DiscImageChef.Checksums
|
||||
else
|
||||
{
|
||||
i = self.bh[bi].halfdigest;
|
||||
if (i != 0)
|
||||
if(i != 0)
|
||||
{
|
||||
if (remain <= 0)
|
||||
if(remain <= 0)
|
||||
throw new Exception("Assertion failed");
|
||||
result[result_off] = (byte)i;
|
||||
if (i < 3 ||
|
||||
if(i < 3 ||
|
||||
result[result_off] != result[result_off - 1] ||
|
||||
result[result_off] != result[result_off - 2] ||
|
||||
result[result_off] != result[result_off - 3])
|
||||
@@ -426,11 +426,11 @@ namespace DiscImageChef.Checksums
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (h != 0)
|
||||
else if(h != 0)
|
||||
{
|
||||
if (self.bh[bi].dlen != 0)
|
||||
if(self.bh[bi].dlen != 0)
|
||||
throw new Exception("Assertion failed");
|
||||
if (remain <= 0)
|
||||
if(remain <= 0)
|
||||
throw new Exception("Assertion failed");
|
||||
result[result_off++] = b64[self.bh[bi].h % 64];
|
||||
/* No need to bother with FUZZY_FLAG_ELIMSEQ, because this
|
||||
@@ -519,9 +519,9 @@ namespace DiscImageChef.Checksums
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
for (int i = 0; i < CString.Length; i++)
|
||||
for(int i = 0; i < CString.Length; i++)
|
||||
{
|
||||
if (CString[i] == 0)
|
||||
if(CString[i] == 0)
|
||||
break;
|
||||
|
||||
sb.Append(Encoding.ASCII.GetString(CString, i, 1));
|
||||
|
||||
Reference in New Issue
Block a user