Java BigInteger Calculate order(BigInteger a, BigInteger p, BigInteger f[], BigInteger e[])

Here you can find the source of order(BigInteger a, BigInteger p, BigInteger f[], BigInteger e[])

Description

Find the order of a in Z_p where p-1 has the factors in array f each with the corresponding exponent in array e

License

Open Source License

Parameter

Parameter Description
a a parameter
p a parameter
f a parameter
e a parameter

Declaration

public static BigInteger order(BigInteger a, BigInteger p, BigInteger f[], BigInteger e[]) 

Method Source Code


//package com.java2s;
/*   Copyright (C) 2013 Marius C. Silaghi
  Author: Marius Silaghi: msilaghi@fit.edu
  Florida Tech, Human Decision Support Systems Laboratory
       //from   w ww. j a  v a2 s .  com
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU Affero General Public License as published by
   the Free Software Foundation; either the current version of the License, or
   (at your option) any later version.
       
  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.
      
  You should have received a copy of the GNU Affero General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.              */

import java.math.BigInteger;

public class Main {
    /**
     * Find the order of a in Z_p where p-1 has the factors in array f
     * each with the corresponding exponent in array e
     * @param a
     * @param p
     * @param f
     * @param e
     * @return
     */
    public static BigInteger order(BigInteger a, BigInteger p, BigInteger f[], BigInteger e[]) {
        BigInteger order = p.subtract(BigInteger.ONE);
        for (int k = 0; k < f.length; k++) {
            int _e = e[k].intValue();
            // could do binary search on e
            for (int i = 0; i < _e; i++) {
                BigInteger exponent = order.divide(f[k]);
                BigInteger test = a.modPow(exponent, p);
                if (BigInteger.ONE.equals(test)) {
                    order = exponent;
                } else
                    break;
            }
        }
        return order;
    }
}

Related

  1. multiply(BigInteger x, BigInteger y)
  2. negative(BigInteger n)
  3. normalizarParaBigInteger(Number numero, RoundingMode modo)
  4. numberToIpv4(BigInteger ipNumber)
  5. numberToShortString(BigInteger number)
  6. parseBigInteger(String s, BigInteger defaultValue)
  7. parseBinaryBigInteger(final byte[] buffer, final int offset, final int length, final boolean negative)
  8. parseScaledNonNegativeBigInteger(String str)
  9. product(final BigInteger min, final BigInteger max)