public void Divide() { //System.Diagnostics.Debugger.Launch(); GaloisField field = new GaloisField(285, 256, 0); GaloisPolynomial divident = new GaloisPolynomial(field, new int[] { 32, 49, 205, 69, 42, 20, 0, 236, 17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }); GaloisPolynomial divider = new GaloisPolynomial(field, new int[] { 1, 119, 66, 83, 120, 119, 22, 197, 83, 249, 41, 143, 134, 85, 53, 125, 99, 79 }); GaloisPolynomial quotient, remainder; divident.Divide(divider, out quotient, out remainder); int[] expectedQuotientCoefficients = new int[] { 32, 119, 212, 254, 109, 212, 30, 95, 117 }; int[] expectedRemainderCoefficients = new int[] { 3, 130, 179, 194, 0, 55, 211, 110, 79, 98, 72, 170, 96, 211, 137, 213 }; Assert.AreEqual(expectedQuotientCoefficients.Length, quotient.Coefficients.Length); Assert.AreEqual(expectedRemainderCoefficients.Length, remainder.Coefficients.Length); for (int i = 0; i < quotient.Coefficients.Length; i++) { Assert.AreEqual(expectedQuotientCoefficients[i], quotient.Coefficients[i]); } for (int i = 0; i < remainder.Coefficients.Length; i++) { Assert.AreEqual(expectedRemainderCoefficients[i], remainder.Coefficients[i]); } }
private void initialize() { m_ExpTable = new int[m_Size]; m_LogTable = new int[m_Size]; int x = 1; for (int i = 0; i < m_Size; i++) { m_ExpTable[i] = x; x <<= 1; if (x >= m_Size) { x ^= m_Primitive; x &= m_Size - 1; } } for (int i = 0; i < m_Size - 1; i++) { m_LogTable[m_ExpTable[i]] = i; } m_Polynomial0 = new GaloisPolynomial(this, new int[] { 0 }); m_Polynomial1 = new GaloisPolynomial(this, new int[] { 1 }); m_Initialized = true; }
public GaloisPolynomial GenerateMonomial(int degree, int coefficient) { ensureInitialized(); if (coefficient == 0) { return(m_Polynomial0); } int[] coefficients = new int[degree + 1]; coefficients[0] = coefficient; GaloisPolynomial polynomial = new GaloisPolynomial(this, coefficients); return(polynomial); }