Example #1
0
        private int ElementOfOrder(int K, int P)
        {
            Random random = new Random();
            int    m      = 0;

            while (m == 0)
            {
                m  = random.Next();
                m %= P - 1;
                if (m < 0)
                {
                    m += P - 1;
                }
            }

            int l = BigMath.Order(m, P);

            while (l % K != 0 || l == 0)
            {
                while (m == 0)
                {
                    m  = random.Next();
                    m %= P - 1;
                    if (m < 0)
                    {
                        m += P - 1;
                    }
                }
                l = BigMath.Order(m, P);
            }

            int r = m;

            l = K / l;

            for (int i = 2; i <= l; i++)
            {
                r *= m;
            }

            return(r);
        }
Example #2
0
        private void ComputeType()
        {
            if ((DegreeN & 7) == 0)
            {
                throw new Exception("The extension degree is divisible by 8!");
            }

            // checking for the type
            int s = 0;
            int k = 0;

            m_Type = 1;

            for (int d = 0; d != 1; m_Type++)
            {
                s = m_Type * DegreeN + 1;
                if (BigMath.IsPrime(s))
                {
                    k = BigMath.Order(2, s);
                    d = BigMath.Gcd(m_Type * DegreeN / k, DegreeN);
                }
            }
            m_Type--;

            if (m_Type == 1)
            {
                s = (DegreeN << 1) + 1;
                if (BigMath.IsPrime(s))
                {
                    k = BigMath.Order(2, s);
                    int d = BigMath.Gcd((DegreeN << 1) / k, DegreeN);
                    if (d == 1)
                    {
                        m_Type++;
                    }
                }
            }
        }