/// <summary> /// Compute the product of this element and <c>factor</c> /// </summary> /// /// <param name="Factor">he factor</param> /// /// <returns>Returns <c>this * factor</c> </returns> public override IGFElement Multiply(IGFElement Factor) { GF2nONBElement result = new GF2nONBElement(this); result.MultiplyThisBy(Factor); return(result); }
/// <summary> /// Compute the sum of this element and <c>Addend</c>. /// </summary> /// /// <param name="Addend">The addend</param> /// /// <returns>Returns <c>this + other</c></returns> public override IGFElement Add(IGFElement Addend) { GF2nONBElement result = new GF2nONBElement(this); result.AddToThis(Addend); return(result); }
/// <summary> /// Compute <c>this + addend</c> (overwrite <c>this</c>) /// </summary> /// /// <param name="Addend">The addend</param> public override void AddToThis(IGFElement Addend) { if (!(Addend is GF2nPolynomialElement)) { throw new Exception(); } if (!mField.Equals(((GF2nPolynomialElement)Addend).mField)) { throw new Exception(); } polynomial.AddToThis(((GF2nPolynomialElement)Addend).polynomial); }
/// <summary> /// Compute <c>this + addend</c> (overwrite <c>this</c>) /// </summary> /// /// <param name="Addend">The addend</param> public override void AddToThis(IGFElement Addend) { if (!(Addend is GF2nONBElement)) { throw new Exception(); } if (!m_Field.Equals(((GF2nONBElement)Addend).m_Field)) { throw new Exception(); } for (int i = 0; i < m_Length; i++) { m_Pol[i] ^= ((GF2nONBElement)Addend).m_Pol[i]; } }
/// <summary> /// Compute <c>this + addend</c> (overwrite <c>this</c>) /// </summary> /// /// <param name="Addend">The addend</param> public override void AddToThis(IGFElement addend) { if (!(addend is GF2nONBElement)) { throw new Exception(); } if (!mField.Equals(((GF2nONBElement)addend).mField)) { throw new Exception(); } for (int i = 0; i < _mLength; i++) { _mPol[i] ^= ((GF2nONBElement)addend)._mPol[i]; } }
/// <summary> /// Compute <c>this * factor</c> (overwrite <c>this</c>). /// </summary> /// /// <param name="Factor">The factor</param> public override void MultiplyThisBy(IGFElement Factor) { if (!(Factor is GF2nPolynomialElement)) { throw new Exception(); } if (!mField.Equals(((GF2nPolynomialElement)Factor).mField)) { throw new Exception(); } if (Equals(Factor)) { SquareThis(); return; } polynomial = polynomial.Multiply(((GF2nPolynomialElement)Factor).polynomial); ReduceThis(); }
/// <summary> /// Compute the product of this element and <c>factor</c> /// </summary> /// /// <param name="Factor">he factor</param> /// /// <returns>Returns <c>this * factor</c> </returns> public abstract IGFElement Multiply(IGFElement Factor);
/// <summary> /// Compute <c>this * factor</c> (overwrite <c>this</c>). /// </summary> /// /// <param name="Factor">The factor</param> public override void MultiplyThisBy(IGFElement Factor) { if (!(Factor is GF2nONBElement)) throw new Exception("The elements have different" + " representation: not yet" + " implemented"); if (!mField.Equals(((GF2nONBElement)Factor).mField)) throw new Exception(); if (Equals(Factor)) { SquareThis(); } else { long[] a = _mPol; long[] b = ((GF2nONBElement)Factor)._mPol; long[] c = new long[_mLength]; int[][] m = ((GF2nONBField)mField).MultM; int degf, degb, s, fielda, fieldb, bita, bitb; degf = _mLength - 1; degb = _mBit - 1; s = 0; long TWOTOMAXLONGM1 = _mBitmask[MAXLONG - 1]; long TWOTODEGB = _mBitmask[degb]; bool old, now; // the product c of a and b (a*b = c) is calculated in mDegree cicles in every // cicle one coefficient of c is calculated and stored k indicates the coefficient for (int k = 0; k < mDegree; k++) { s = 0; for (int i = 0; i < mDegree; i++) { fielda = _mIBY64[i]; bita = i & (MAXLONG - 1); fieldb = _mIBY64[m[i][0]]; bitb = m[i][0] & (MAXLONG - 1); if ((a[fielda] & _mBitmask[bita]) != 0) { if ((b[fieldb] & _mBitmask[bitb]) != 0) s ^= 1; if (m[i][1] != -1) { fieldb = _mIBY64[m[i][1]]; bitb = m[i][1] & (MAXLONG - 1); if ((b[fieldb] & _mBitmask[bitb]) != 0) s ^= 1; } } } fielda = _mIBY64[k]; bita = k & (MAXLONG - 1); if (s != 0) c[fielda] ^= _mBitmask[bita]; // Circular shift of x and y one bit to the right, respectively if (_mLength > 1) { old = (a[degf] & 1) == 1; for (int i = degf - 1; i >= 0; i--) { now = (a[i] & 1) != 0; a[i] = IntUtils.URShift(a[i], 1); if (old) a[i] ^= TWOTOMAXLONGM1; old = now; } a[degf] = IntUtils.URShift(a[degf], 1); if (old) a[degf] ^= TWOTODEGB; old = (b[degf] & 1) == 1; for (int i = degf - 1; i >= 0; i--) { now = (b[i] & 1) != 0; b[i] = IntUtils.URShift(b[i], 1); if (old) b[i] ^= TWOTOMAXLONGM1; old = now; } b[degf] = IntUtils.URShift(b[degf], 1); if (old) b[degf] ^= TWOTODEGB; } else { old = (a[0] & 1) == 1; a[0] = IntUtils.URShift(a[0], 1); if (old) a[0] ^= TWOTODEGB; old = (b[0] & 1) == 1; b[0] = IntUtils.URShift(b[0], 1); if (old) b[0] ^= TWOTODEGB; } } Assign(c); } }
/// <summary> /// Compute <c>this + addend</c> (overwrite <c>this</c>) /// </summary> /// /// <param name="Addend">The addend</param> public abstract void AddToThis(IGFElement Addend);
/// <summary> /// Compute <c>this + addend</c> (overwrite <c>this</c>) /// </summary> /// /// <param name="Addend">The addend</param> public override void AddToThis(IGFElement Addend) { if (!(Addend is GF2nONBElement)) throw new Exception(); if (!mField.Equals(((GF2nONBElement)Addend).mField)) throw new Exception(); for (int i = 0; i < _mLength; i++) _mPol[i] ^= ((GF2nONBElement)Addend)._mPol[i]; }
/// <summary> /// Compute <c>this * factor</c> (overwrite <c>this</c>). /// </summary> /// /// <param name="Factor">The factor</param> public abstract void MultiplyThisBy(IGFElement Factor);
/// <summary> /// Compute the sum of this element and <c>Addend</c>. /// </summary> /// /// <param name="Addend">The addend</param> /// /// <returns>Returns <c>this + other</c></returns> public abstract IGFElement Add(IGFElement Addend);
/// <summary> /// Compute the sum of this element and <c>Addend</c>. /// </summary> /// /// <param name="Addend">The addend</param> /// /// <returns>Returns <c>this + other</c></returns> public override IGFElement Add(IGFElement Addend) { GF2nPolynomialElement result = new GF2nPolynomialElement(this); result.AddToThis(Addend); return result; }
/// <summary> /// Compute the product of this element and <c>factor</c> /// </summary> /// /// <param name="Factor">he factor</param> /// /// <returns>Returns <c>this * factor</c> </returns> public override IGFElement Multiply(IGFElement Factor) { GF2nPolynomialElement result = new GF2nPolynomialElement(this); result.MultiplyThisBy(Factor); return result; }
/// <summary> /// Compute the difference of this element and <c>minuend</c> /// </summary> /// /// <param name="Minuend">The minuend</param> /// /// <returns>Returns <c>this - minuend</c> (newly created)</returns> public IGFElement Subtract(IGFElement Minuend) { return(Add(Minuend)); }
/// <summary> /// Compute the difference of this element and <c>minuend</c>, overwriting this element /// </summary> /// /// <param name="Minuend">The minuend</param> public void SubtractFromThis(IGFElement Minuend) { AddToThis(Minuend); }
/// <summary> /// Compute <c>this * factor</c> (overwrite <c>this</c>). /// </summary> /// /// <param name="Factor">The factor</param> public override void MultiplyThisBy(IGFElement Factor) { if (!(Factor is GF2nONBElement)) { throw new Exception("The elements have different" + " representation: not yet" + " implemented"); } if (!m_Field.Equals(((GF2nONBElement)Factor).m_Field)) { throw new Exception(); } if (Equals(Factor)) { SquareThis(); } else { long[] a = m_Pol; long[] b = ((GF2nONBElement)Factor).m_Pol; long[] c = new long[m_Length]; int[][] m = ((GF2nONBField)m_Field).m_MultM; int degf, degb, s, fielda, fieldb, bita, bitb; degf = m_Length - 1; degb = m_Bit - 1; s = 0; long TWOTOMAXLONGM1 = _mBitmask[MAXLONG - 1]; long TWOTODEGB = _mBitmask[degb]; bool old, now; // the product c of a and b (a*b = c) is calculated in m_Degree cicles in every // cicle one coefficient of c is calculated and stored k indicates the coefficient for (int k = 0; k < m_Degree; k++) { s = 0; for (int i = 0; i < m_Degree; i++) { fielda = _mIBY64[i]; bita = i & (MAXLONG - 1); fieldb = _mIBY64[m[i][0]]; bitb = m[i][0] & (MAXLONG - 1); if ((a[fielda] & _mBitmask[bita]) != 0) { if ((b[fieldb] & _mBitmask[bitb]) != 0) { s ^= 1; } if (m[i][1] != -1) { fieldb = _mIBY64[m[i][1]]; bitb = m[i][1] & (MAXLONG - 1); if ((b[fieldb] & _mBitmask[bitb]) != 0) { s ^= 1; } } } } fielda = _mIBY64[k]; bita = k & (MAXLONG - 1); if (s != 0) { c[fielda] ^= _mBitmask[bita]; } // Circular shift of x and y one bit to the right, respectively if (m_Length > 1) { old = (a[degf] & 1) == 1; for (int i = degf - 1; i >= 0; i--) { now = (a[i] & 1) != 0; a[i] = IntUtils.URShift(a[i], 1); if (old) { a[i] ^= TWOTOMAXLONGM1; } old = now; } a[degf] = IntUtils.URShift(a[degf], 1); if (old) { a[degf] ^= TWOTODEGB; } old = (b[degf] & 1) == 1; for (int i = degf - 1; i >= 0; i--) { now = (b[i] & 1) != 0; b[i] = IntUtils.URShift(b[i], 1); if (old) { b[i] ^= TWOTOMAXLONGM1; } old = now; } b[degf] = IntUtils.URShift(b[degf], 1); if (old) { b[degf] ^= TWOTODEGB; } } else { old = (a[0] & 1) == 1; a[0] = IntUtils.URShift(a[0], 1); if (old) { a[0] ^= TWOTODEGB; } old = (b[0] & 1) == 1; b[0] = IntUtils.URShift(b[0], 1); if (old) { b[0] ^= TWOTODEGB; } } } Assign(c); } }
/// <summary> /// Compute <c>this + addend</c> (overwrite <c>this</c>) /// </summary> /// /// <param name="Addend">The addend</param> public override void AddToThis(IGFElement Addend) { if (!(Addend is GF2nPolynomialElement)) throw new Exception(); if (!mField.Equals(((GF2nPolynomialElement)Addend).mField)) throw new Exception(); polynomial.AddToThis(((GF2nPolynomialElement)Addend).polynomial); }
/// <summary> /// Compute the difference of this element and <c>minuend</c> /// </summary> /// /// <param name="Minuend">The minuend</param> /// /// <returns>Returns <c>this - minuend</c> (newly created)</returns> public IGFElement Subtract(IGFElement Minuend) { return Add(Minuend); }
/// <summary> /// Compute <c>this * factor</c> (overwrite <c>this</c>). /// </summary> /// /// <param name="Factor">The factor</param> public override void MultiplyThisBy(IGFElement Factor) { if (!(Factor is GF2nPolynomialElement)) throw new Exception(); if (!mField.Equals(((GF2nPolynomialElement)Factor).mField)) throw new Exception(); if (Equals(Factor)) { SquareThis(); return; } polynomial = polynomial.Multiply(((GF2nPolynomialElement)Factor).polynomial); ReduceThis(); }