Norm() public static method

public static Norm ( sbyte mu, ZTauElement lambda ) : BigInteger
mu sbyte
lambda ZTauElement
return BigInteger
Beispiel #1
0
        public static sbyte[] TauAdicNaf(sbyte mu, ZTauElement lambda)
        {
            if (mu != 1 && mu != -1)
            {
                throw new ArgumentException("mu must be 1 or -1");
            }
            BigInteger bigInteger = Tnaf.Norm(mu, lambda);
            int        bitLength  = bigInteger.BitLength;
            int        num        = (bitLength > 30) ? (bitLength + 4) : 34;

            sbyte[]    array       = new sbyte[num];
            int        num2        = 0;
            int        num3        = 0;
            BigInteger bigInteger2 = lambda.u;
            BigInteger bigInteger3 = lambda.v;

            while (!bigInteger2.Equals(BigInteger.Zero) || !bigInteger3.Equals(BigInteger.Zero))
            {
                if (bigInteger2.TestBit(0))
                {
                    array[num2] = (sbyte)BigInteger.Two.Subtract(bigInteger2.Subtract(bigInteger3.ShiftLeft(1)).Mod(Tnaf.Four)).IntValue;
                    if (array[num2] == 1)
                    {
                        bigInteger2 = bigInteger2.ClearBit(0);
                    }
                    else
                    {
                        bigInteger2 = bigInteger2.Add(BigInteger.One);
                    }
                    num3 = num2;
                }
                else
                {
                    array[num2] = 0;
                }
                BigInteger bigInteger4 = bigInteger2;
                BigInteger bigInteger5 = bigInteger2.ShiftRight(1);
                if (mu == 1)
                {
                    bigInteger2 = bigInteger3.Add(bigInteger5);
                }
                else
                {
                    bigInteger2 = bigInteger3.Subtract(bigInteger5);
                }
                bigInteger3 = bigInteger4.ShiftRight(1).Negate();
                num2++;
            }
            num3++;
            sbyte[] array2 = new sbyte[num3];
            Array.Copy(array, 0, array2, 0, num3);
            return(array2);
        }
Beispiel #2
0
        public static sbyte[] TauAdicWNaf(sbyte mu, ZTauElement lambda, sbyte width, BigInteger pow2w, BigInteger tw, ZTauElement[] alpha)
        {
            if (mu != 1 && mu != -1)
            {
                throw new ArgumentException("mu must be 1 or -1");
            }
            BigInteger bigInteger = Tnaf.Norm(mu, lambda);
            int        bitLength  = bigInteger.BitLength;
            int        num        = (bitLength > 30) ? (bitLength + 4 + (int)width) : ((int)(34 + width));

            sbyte[]    array       = new sbyte[num];
            BigInteger value       = pow2w.ShiftRight(1);
            BigInteger bigInteger2 = lambda.u;
            BigInteger bigInteger3 = lambda.v;
            int        num2        = 0;

            while (!bigInteger2.Equals(BigInteger.Zero) || !bigInteger3.Equals(BigInteger.Zero))
            {
                if (bigInteger2.TestBit(0))
                {
                    BigInteger bigInteger4 = bigInteger2.Add(bigInteger3.Multiply(tw)).Mod(pow2w);
                    sbyte      b;
                    if (bigInteger4.CompareTo(value) >= 0)
                    {
                        b = (sbyte)bigInteger4.Subtract(pow2w).IntValue;
                    }
                    else
                    {
                        b = (sbyte)bigInteger4.IntValue;
                    }
                    array[num2] = b;
                    bool flag = true;
                    if (b < 0)
                    {
                        flag = false;
                        b    = -b;
                    }
                    if (flag)
                    {
                        bigInteger2 = bigInteger2.Subtract(alpha[(int)b].u);
                        bigInteger3 = bigInteger3.Subtract(alpha[(int)b].v);
                    }
                    else
                    {
                        bigInteger2 = bigInteger2.Add(alpha[(int)b].u);
                        bigInteger3 = bigInteger3.Add(alpha[(int)b].v);
                    }
                }
                else
                {
                    array[num2] = 0;
                }
                BigInteger bigInteger5 = bigInteger2;
                if (mu == 1)
                {
                    bigInteger2 = bigInteger3.Add(bigInteger2.ShiftRight(1));
                }
                else
                {
                    bigInteger2 = bigInteger3.Subtract(bigInteger2.ShiftRight(1));
                }
                bigInteger3 = bigInteger5.ShiftRight(1).Negate();
                num2++;
            }
            return(array);
        }