Esempio n. 1
0
        public static bool Vn(BigInt n, BigInt D)
        {
            BigInt P = new BigInt("1");
            BigInt Q = divide(subtract(P, D), new BigInt("4"));

            Console.WriteLine("Q:" + Q.toString());
            BigInt U        = new BigInt("1");
            BigInt V        = new BigInt("1");
            BigInt k        = new BigInt("1");
            BigInt one      = new BigInt("1");
            BigInt two      = new BigInt("2");
            BigInt nPlusOne = add(one, n);
            string bin      = nPlusOne.ToBinary();

            Console.WriteLine("n+1 bin: " + bin);
            BigInt U_temp = new BigInt(U.toString());
            BigInt V_temp = new BigInt(V.toString());
            int    i      = 0;

            while (i < bin.Length)
            {
                //if ((bin[i] == '1') && (i == 0))
                //{
                //    U = U2k(U_temp, V_temp);
                //    V = V2k(V_temp, Q, k);
                //}
                if ((bin[i] == '1') && (i != 0))
                {
                    U      = U2k(U_temp, V_temp);
                    V      = V2k(V_temp, Q, k);
                    U_temp = new BigInt(U.toString());
                    V_temp = new BigInt(V.toString());
                    //Console.WriteLine("V:" + V.toString());
                    //Console.WriteLine("U" + U.toString());
                    k = multiply(two, k);
                    U = U2kPlusOne(U_temp, V_temp, P);
                    V = V2kPlusOne(U_temp, V_temp, P, D);
                    k = add(k, one);
                }
                ;
                if ((bin[i] == '0'))
                {
                    U = U2k(U_temp, V_temp);
                    V = V2k(V_temp, Q, k);
                    k = multiply(two, k);
                }
                ;
                //Console.WriteLine("V:" + V.toString());
                //Console.WriteLine("U" + U.toString());
                i++;
                U_temp = new BigInt(U.toString());
                V_temp = new BigInt(V.toString());
            }
            Console.WriteLine("k: " + k.toString());
            Console.WriteLine("Vn+1 mod n: " + mod(V, n).toString());
            BigInt compare = multiply(two, Q);

            while (less(compare, new BigInt("0")))
            {
                compare = add(compare, n);
            }
            Console.WriteLine("Result:");
            return(equal(mod(V, n), compare));
        }