Java examples for java.lang:Math Value
Returns the value obtained from applying the Euler totient function to an integer value .
/*/*from w w w. j a v a 2 s . c o m*/ * UniCrypt * * UniCrypt(tm) : Cryptographical framework allowing the implementation of cryptographic protocols e.g. e-voting * Copyright (C) 2014 Bern University of Applied Sciences (BFH), Research Institute for * Security in the Information Society (RISIS), E-Voting Group (EVG) * Quellgasse 21, CH-2501 Biel, Switzerland * * Licensed under Dual License consisting of: * 1. GNU Affero General Public License (AGPL) v3 * and * 2. Commercial license * * * 1. 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 version 3 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 Affero 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, see <http://www.gnu.org/licenses/>. * * * 2. Licensees holding valid commercial licenses for UniCrypt may use this file in * accordance with the commercial license agreement provided with the * Software or, alternatively, in accordance with the terms contained in * a written agreement between you and Bern University of Applied Sciences (BFH), Research Institute for * Security in the Information Society (RISIS), E-Voting Group (EVG) * Quellgasse 21, CH-2501 Biel, Switzerland. * * * For further information contact <e-mail: unicrypt@bfh.ch> * * * Redistributions of files must retain the above copyright notice. */ //package com.java2s; import java.math.BigInteger; public class Main { /** * Returns the value obtained from applying the Euler totient function to an integer {@literal value}. * <dt><b>Preconditions:</b></dt> * <dd>{@literal primeFactorSet} is the complete set of prime factors of {@literal value}.</dd> * <p> * @param value The input value * @param primeFactorSet The prime factors of {@literal value} * @return the result of applying the Euler totient function to {@literal value} * @throws IllegalArgumentException if {@literal value} is {@literal null}, {@literal 0}, or negative * @throws IllegalArgumentException if {@literal primeFactorSet} is null or if {@literal primeFactorSet} contains * {@literal null} * @see MathUtil#arePrimeFactors(BigInteger, BigInteger[]) * @see MathUtil#removeDuplicates(BigInteger[]) * @see "Handbook of Applied Cryptography, Fact 2.101 (iii)" */ public static BigInteger eulerFunction(final BigInteger value, final BigInteger... primeFactorSet) { if (value == null || value.signum() == 0 || value.signum() == -1 || primeFactorSet == null) { throw new IllegalArgumentException(); } BigInteger product1 = BigInteger.ONE; BigInteger product2 = BigInteger.ONE; for (final BigInteger prime : primeFactorSet) { if (prime == null) { throw new IllegalArgumentException(); } product1 = product1.multiply(prime); product2 = product2.multiply(prime.subtract(BigInteger.ONE)); } return value.multiply(product2).divide(product1); } }