ShiftLeft() public méthode

public ShiftLeft ( int n ) : IntArray
n int
Résultat IntArray
        public IntArray Multiply(IntArray other, int m)
        {
            // Lenght of c is 2m bits rounded up to the next int (32 bit)
            int t = (m + 31) >> 5;

            if (m_ints.Length < t)
            {
                m_ints = resizedInts(t);
            }

            IntArray b = new IntArray(other.resizedInts(other.Length + 1));
            IntArray c = new IntArray((m + m + 31) >> 5);
            // IntArray c = new IntArray(t + t);
            int testBit = 1;

            for (int k = 0; k < 32; k++)
            {
                for (int j = 0; j < t; j++)
                {
                    if ((m_ints[j] & testBit) != 0)
                    {
                        // The kth bit of m_ints[j] is set
                        c.AddShifted(b, j);
                    }
                }
                testBit <<= 1;
                b.ShiftLeft();
            }
            return(c);
        }
Exemple #2
0
        public override ECFieldElement Invert()
        {
            IntArray uz = (IntArray)this.x.Clone();

            IntArray vz = new IntArray(t);

            vz.SetBit(m);
            vz.SetBit(0);
            vz.SetBit(this.k1);
            if (this.representation == Ppb)
            {
                vz.SetBit(this.k2);
                vz.SetBit(this.k3);
            }

            IntArray g1z = new IntArray(t);

            g1z.SetBit(0);
            IntArray g2z = new IntArray(t);

            while (uz.GetUsedLength() > 0)
            {
                int j = uz.BitLength - vz.BitLength;

                if (j < 0)
                {
                    IntArray uzCopy = uz;
                    uz = vz;
                    vz = uzCopy;

                    IntArray g1zCopy = g1z;
                    g1z = g2z;
                    g2z = g1zCopy;

                    j = -j;
                }

                int      jInt    = j >> 5;
                int      jBit    = j & 0x1F;
                IntArray vzShift = vz.ShiftLeft(jBit);
                uz.AddShifted(vzShift, jInt);

                IntArray g2zShift = g2z.ShiftLeft(jBit);
                g1z.AddShifted(g2zShift, jInt);
            }

            return(new F2mFieldElement(this.m, this.k1, this.k2, this.k3, g2z));
        }
		public IntArray Multiply(IntArray other, int m)
		{
			// Lenght of c is 2m bits rounded up to the next int (32 bit)
			int t = (m + 31) >> 5;
			if (m_ints.Length < t)
			{
				m_ints = resizedInts(t);
			}

			IntArray b = new IntArray(other.resizedInts(other.Length + 1));
			IntArray c = new IntArray((m + m + 31) >> 5);
			// IntArray c = new IntArray(t + t);
			int testBit = 1;
			for (int k = 0; k < 32; k++)
			{
				for (int j = 0; j < t; j++)
				{
					if ((m_ints[j] & testBit) != 0)
					{
						// The kth bit of m_ints[j] is set
						c.AddShifted(b, j);
					}
				}
				testBit <<= 1;
				b.ShiftLeft();
			}
			return c;
		}
Exemple #4
0
		public override ECFieldElement Invert()
		{
			// Inversion in F2m using the extended Euclidean algorithm
			// Input: A nonzero polynomial a(z) of degree at most m-1
			// Output: a(z)^(-1) mod f(z)

			// u(z) := a(z)
            IntArray uz = (IntArray)this.x.Copy();

			// v(z) := f(z)
			IntArray vz = new IntArray(t);
			vz.SetBit(m);
			vz.SetBit(0);
			vz.SetBit(this.k1);
			if (this.representation == Ppb)
			{
				vz.SetBit(this.k2);
				vz.SetBit(this.k3);
			}

			// g1(z) := 1, g2(z) := 0
			IntArray g1z = new IntArray(t);
			g1z.SetBit(0);
			IntArray g2z = new IntArray(t);

			// while u != 0
			while (uz.GetUsedLength() > 0)
//            while (uz.bitLength() > 1)
			{
				// j := deg(u(z)) - deg(v(z))
				int j = uz.BitLength - vz.BitLength;

				// If j < 0 then: u(z) <-> v(z), g1(z) <-> g2(z), j := -j
				if (j < 0)
				{
                    IntArray uzCopy = uz;
					uz = vz;
					vz = uzCopy;

                    IntArray g1zCopy = g1z;
					g1z = g2z;
					g2z = g1zCopy;

					j = -j;
				}

				// u(z) := u(z) + z^j * v(z)
				// Note, that no reduction modulo f(z) is required, because
				// deg(u(z) + z^j * v(z)) <= max(deg(u(z)), j + deg(v(z)))
				// = max(deg(u(z)), deg(u(z)) - deg(v(z)) + deg(v(z))
				// = deg(u(z))
				// uz = uz.xor(vz.ShiftLeft(j));
				// jInt = n / 32
				int jInt = j >> 5;
				// jInt = n % 32
				int jBit = j & 0x1F;
				IntArray vzShift = vz.ShiftLeft(jBit);
				uz.AddShifted(vzShift, jInt);

				// g1(z) := g1(z) + z^j * g2(z)
//                g1z = g1z.xor(g2z.ShiftLeft(j));
				IntArray g2zShift = g2z.ShiftLeft(jBit);
				g1z.AddShifted(g2zShift, jInt);
			}
			return new F2mFieldElement(this.m, this.k1, this.k2, this.k3, g2z);
		}
Exemple #5
0
        public override ECFieldElement Invert()
        {
            // Inversion in F2m using the extended Euclidean algorithm
            // Input: A nonzero polynomial a(z) of degree at most m-1
            // Output: a(z)^(-1) mod f(z)

            // u(z) := a(z)
            var uz = _x.Copy();

            // v(z) := f(z)
            var vz = new IntArray(_t);

            vz.SetBit(_m);
            vz.SetBit(0);
            vz.SetBit(this._k1);
            if (this._representation == Ppb)
            {
                vz.SetBit(this._k2);
                vz.SetBit(this._k3);
            }

            // g1(z) := 1, g2(z) := 0
            var g1Z = new IntArray(_t);

            g1Z.SetBit(0);
            var g2Z = new IntArray(_t);

            // while u != 0
            while (uz.GetUsedLength() > 0)
            //            while (uz.bitLength() > 1)
            {
                // j := deg(u(z)) - deg(v(z))
                var j = uz.BitLength - vz.BitLength;

                // If j < 0 then: u(z) <-> v(z), g1(z) <-> g2(z), j := -j
                if (j < 0)
                {
                    var uzCopy = uz;
                    uz = vz;
                    vz = uzCopy;

                    var g1ZCopy = g1Z;
                    g1Z = g2Z;
                    g2Z = g1ZCopy;

                    j = -j;
                }

                // u(z) := u(z) + z^j * v(z)
                // Note, that no reduction modulo f(z) is required, because
                // deg(u(z) + z^j * v(z)) <= max(deg(u(z)), j + deg(v(z)))
                // = max(deg(u(z)), deg(u(z)) - deg(v(z)) + deg(v(z))
                // = deg(u(z))
                // uz = uz.xor(vz.ShiftLeft(j));
                // jInt = n / 32
                var jInt = j >> 5;
                // jInt = n % 32
                var jBit    = j & 0x1F;
                var vzShift = vz.ShiftLeft(jBit);
                uz.AddShifted(vzShift, jInt);

                // g1(z) := g1(z) + z^j * g2(z)
                //                g1z = g1z.xor(g2z.ShiftLeft(j));
                var g2ZShift = g2Z.ShiftLeft(jBit);
                g1Z.AddShifted(g2ZShift, jInt);
            }
            return(new F2MFieldElement(this._m, this._k1, this._k2, this._k3, g2Z));
        }