示例#1
0
        static public Ep MsgToEp(BigInteger m)
        {
            BigInteger z;

            for (int index = 0; index < 100; index++)
            {
                BigInteger x = (100 * m) + index;
                z = x ^ 3 + ECC._a * x + ECC._b;
                if (IntegerCalclator.LegendreSymbol(z, ECC._p))
                {
                    BigInteger y = IntegerCalclator.SqrtMod(z, ECC._p);
                    return(new Ep(x, y));
                }
            }

            //エラー
            return(new Ep());
        }
示例#2
0
        //コンストラスタ:初期位置を入力
        public Ep(BigInteger m)
        {
            BigInteger z;
            BigInteger y = 0;
            BigInteger x = 0;

            for (int index = 0; index < 100; index++)
            {
                x = (100 * m) + index;
                z = (x ^ 3) + (ECC.a * x) + ECC.b;                //z=y^2に注意
                if (IntegerCalclator.LegendreSymbol(z, ECC.p))
                {
                    y = IntegerCalclator.SqrtMod(z, ECC.p);
                    break;
                }
            }
            this.x = x;
            this.y = y;
        }
示例#3
0
        //平方剰余計算テスト
        public void SqrtModTest()
        {
            Console.Write("a= ");
            string     strA = Console.ReadLine();
            BigInteger a    = BigInteger.Parse(strA);

            Console.Write("p= ");
            string     strP = Console.ReadLine();
            BigInteger p    = BigInteger.Parse(strP);

            if (IntegerCalclator.LegendreSymbol(a, p))
            {
                BigInteger x = IntegerCalclator.SqrtMod(a, p);
                Console.Write("Answer: ");
                Console.WriteLine(x.ToString());
            }
            else
            {
                Console.WriteLine("aはpの倍数か平方非剰余です");
            }
        }