Here you can find the source of isRootInQuadraticResidues(BigInteger n, BigInteger p)
public static boolean isRootInQuadraticResidues(BigInteger n, BigInteger p)
//package com.java2s; //License from project: Apache License import java.math.BigInteger; public class Main { public static boolean isRootInQuadraticResidues(BigInteger n, BigInteger p) { BigInteger tow = BigInteger.valueOf(2); BigInteger x = n.mod(p);/*from w w w. jav a2s . c o m*/ if (p.equals(tow)) { return x.mod(tow).equals(BigInteger.ONE); } BigInteger exponent = p.subtract(BigInteger.ONE).divide(tow); return x.modPow(exponent, p).equals(BigInteger.ONE); } }