private Crc32(Crc32Formula formula, uint[] polynomialTable, uint initValue, uint xorOut) { _polynomialTable = polynomialTable ?? throw new ArgumentNullException(nameof(polynomialTable)); _formula = formula; _initValue = initValue; _xorOut = xorOut; }
private static uint[] InitializeTable(Crc32Formula formula, uint polynomial) { if (formula == Crc32Formula.Normal && polynomial == DefaultPolynomial) { return(_defaultCrc32Table); } if (formula == Crc32Formula.Reflected && polynomial == DefaultReflectedPolynomial) { return(_defaultReflectedCrc32Table); } var polynomialTable = new uint[256]; for (uint i = 0; i < 256; i++) { uint entry; if (formula == Crc32Formula.Normal) { entry = i << 24; for (var j = 0; j < 8; j++) { if ((entry & 0x80000000) != 0) { entry = (entry << 1) ^ polynomial; } else { entry <<= 1; } } } else { entry = i; for (var j = 0; j < 8; j++) { if ((entry & 1) == 1) { entry = (entry >> 1) ^ polynomial; } else { entry >>= 1; } } } polynomialTable[i] = entry; } return(polynomialTable); }
public static Crc32 Create(Crc32Formula formula, uint polynomial) { var table = InitializeTable(formula, polynomial); return(new Crc32(formula, table)); }
public static Crc32 Create(Crc32Formula formula) { return(new Crc32(formula, formula == Crc32Formula.Normal ? _defaultCrc32Table : _defaultReflectedCrc32Table)); }
private Crc32(Crc32Formula formula, uint[] polynomialTable) { _polynomialTable = polynomialTable ?? throw new ArgumentNullException(nameof(polynomialTable)); _formula = formula; }
public static Crc32 Create(Crc32Formula formula, uint polynomial, uint initValue = 0xFFFFFFFF, uint xorOut = 0xFFFFFFFF) { var table = InitializeTable(formula, polynomial); return(new Crc32(formula, table, initValue, xorOut)); }