本文整理了Java中java.math.BigInteger.probablePrime()
方法的一些代码示例,展示了BigInteger.probablePrime()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BigInteger.probablePrime()
方法的具体详情如下:
包路径:java.math.BigInteger
类名称:BigInteger
方法名:probablePrime
[英]Returns a random positive BigInteger instance in the range [0, pow(2, bitLength)-1] which is probably prime. The probability that the returned BigInteger is prime is greater than 1 - 1/2100).
[中]返回范围为[0,pow(2,bitLength)-1]的随机正BigInteger实例,该范围可能为素数。返回的BigInteger为素数的概率大于1-1/2100)。
代码示例来源:origin: kevin-wayne/algs4
private static long longRandomPrime() {
BigInteger prime = BigInteger.probablePrime(31, new Random());
return prime.longValue();
}
代码示例来源:origin: apache/geode
private static Callable<BigInteger> generateProbablePrimes() {
return () -> {
Random random = new Random();
// To keep the CPU busy, we must prevent the Java and JIT compilers from optimizing this loop
// out of existence. To do that, we save the the most recently generated prime, and return it
// when the task is cancelled. Our assumption is that the compilers can't predict that the
// return value is unused, and is therefore forced to calculate a new prime on each iteration.
BigInteger prime = BigInteger.valueOf(0);
while (!Thread.currentThread().isInterrupted()) {
prime = BigInteger.probablePrime(1000, random);
}
return prime;
};
}
代码示例来源:origin: google/guava
@GwtIncompatible // isPrime is GWT-incompatible
public void testIsPrimeOnRandomComposites() {
Random rand = new Random(1);
for (int bits = 5; bits < 32; bits++) {
for (int i = 0; i < 100; i++) {
long p = BigInteger.probablePrime(bits, rand).longValue();
long q = BigInteger.probablePrime(bits, rand).longValue();
assertFalse(LongMath.isPrime(p * q));
}
}
}
代码示例来源:origin: google/guava
@GwtIncompatible // isPrime is GWT-incompatible
public void testIsPrimeOnRandomPrimes() {
Random rand = new Random(1);
for (int bits = 10; bits < 63; bits++) {
for (int i = 0; i < 100; i++) {
long p = BigInteger.probablePrime(bits, rand).longValue();
assertTrue(LongMath.isPrime(p));
}
}
}
代码示例来源:origin: ethereum/ethereumj
private List<BlockInfo> generateBlockInfos(int count) {
List<BlockInfo> blockInfos = new ArrayList<>();
for (int i = 0; i < count; i++) {
BlockInfo blockInfo = new BlockInfo();
blockInfo.setHash(sha3(ByteUtil.intToBytes(i)));
blockInfo.setTotalDifficulty(BigInteger.probablePrime(512, rnd));
blockInfo.setMainChain(rnd.nextBoolean());
blockInfos.add(blockInfo);
}
return blockInfos;
}
代码示例来源:origin: stackoverflow.com
public void run() {
while(true)
BigInteger.probablePrime(MAX_PRIORITY, new Random());
};
}.start();
代码示例来源:origin: stackoverflow.com
int bitLength = 1024;
SecureRandom rnd = new SecureRandom();
BigInteger p = BigInteger.probablePrime(bitLength, rnd);
BigInteger g = BigInteger.probablePrime(bitLength, rnd);
代码示例来源:origin: timtiemens/secretshare
public static BigInteger createPrimeBigger(BigInteger valueThatDeterminesNumberOfBits,
Random random)
{
int numbits = valueThatDeterminesNumberOfBits.bitLength() + 1;
BigInteger ret = BigInteger.probablePrime(numbits, random);
return ret;
}
代码示例来源:origin: stackoverflow.com
BigInteger definitePrime(int bits, Random rnd) {
BigInteger prime = new BigInteger("4");
while(!isPrime(prime)) prime = BigInteger.probablePrime(bits,rnd);
return prime;
}
代码示例来源:origin: com.musala.atmosphere/atmosphere-bitmap-comparison
/** generate a random 31 bit prime **/
private static long longRandomPrime() {
BigInteger prime = BigInteger.probablePrime(31, new Random());
return prime.longValue();
}
代码示例来源:origin: edu.princeton.cs/algs4
private static long longRandomPrime() {
BigInteger prime = BigInteger.probablePrime(31, new Random());
return prime.longValue();
}
代码示例来源:origin: brianway/algorithms-learning
private static long longRandomPrime() {
BigInteger prime = BigInteger.probablePrime(31, new Random());
return prime.longValue();
}
代码示例来源:origin: com.wizzardo.tools/tools-security
public RSA(int n) {
this.n = n;
BigInteger p = BigInteger.probablePrime(n / 2, random);
BigInteger q = BigInteger.probablePrime(n / 2, random);
BigInteger phi = (p.subtract(one)).multiply(q.subtract(one));
modulus = p.multiply(q);
publicKey = new BigInteger("65537"); // common value in practice = 2^16 + 1
privateKey = publicKey.modInverse(phi);
}
代码示例来源:origin: wizzardo/tools
public RSA(int n) {
this.n = n;
BigInteger p = BigInteger.probablePrime(n / 2, random);
BigInteger q = BigInteger.probablePrime(n / 2, random);
BigInteger phi = (p.subtract(one)).multiply(q.subtract(one));
modulus = p.multiply(q);
publicKey = new BigInteger("65537"); // common value in practice = 2^16 + 1
privateKey = publicKey.modInverse(phi);
}
代码示例来源:origin: SomMeri/matasano-cryptopals-solutions
private void crashingGenerateKeyPair(SecureRandom random, int primesBits) {
BigInteger p = BigInteger.probablePrime(primesBits, random);
BigInteger q = BigInteger.probablePrime(primesBits, random);
n = p.multiply(q);
BigInteger et = p.add(BigInteger.ONE.negate()).multiply(q.add(BigInteger.ONE.negate()));
e = BigInteger.valueOf(3);
d = e.modInverse(et);
}
代码示例来源:origin: stackoverflow.com
BigInteger e = new BigInteger("65537"); //to make the compiler happy
BigInteger counter = (BigInteger.probablePrime(128, random)).mod(phi);
while(counter.intValue() > 2)
{
if((e.gcd(phi)).intValue() == 1)
{
e = counter;
break;
}
counter = counter.subtract(BigInteger.ONE);
}
代码示例来源:origin: com.google.guava/guava-tests
@GwtIncompatible // isPrime is GWT-incompatible
public void testIsPrimeOnRandomComposites() {
Random rand = new Random(1);
for (int bits = 5; bits < 32; bits++) {
for (int i = 0; i < 100; i++) {
long p = BigInteger.probablePrime(bits, rand).longValue();
long q = BigInteger.probablePrime(bits, rand).longValue();
assertFalse(LongMath.isPrime(p * q));
}
}
}
代码示例来源:origin: com.google.guava/guava-tests
@GwtIncompatible // isPrime is GWT-incompatible
public void testIsPrimeOnRandomPrimes() {
Random rand = new Random(1);
for (int bits = 10; bits < 63; bits++) {
for (int i = 0; i < 100; i++) {
long p = BigInteger.probablePrime(bits, rand).longValue();
assertTrue(LongMath.isPrime(p));
}
}
}
代码示例来源:origin: org.eclipse.microprofile.jwt/microprofile-jwt-auth-tck
@Test(groups = TCKConstants.TEST_GROUP_DEBUG,
description = "Validate how to use the HS256 signature alg")
public void testHS256() throws Exception {
JWTClaimsSet claimsSet = JWTClaimsSet.parse("{\"sub\":\"jdoe\"}");
SignedJWT signedJWT = new SignedJWT(new JWSHeader(JWSAlgorithm.HS256), claimsSet);
SecureRandom random = new SecureRandom();
BigInteger secret = BigInteger.probablePrime(256, random);
JWSSigner signer = new MACSigner(secret.toByteArray());
signedJWT.sign(signer);
}
代码示例来源:origin: apache/ace
private X509Certificate generateRootCertificate(String commonName, Date notBefore, Date notAfter) throws Exception {
X500Name issuer = new X500Name(commonName);
BigInteger serial = BigInteger.probablePrime(16, new Random());
SubjectPublicKeyInfo pubKeyInfo = convertToSubjectPublicKeyInfo(m_caKey.getPublic());
X509v3CertificateBuilder builder = new X509v3CertificateBuilder(issuer, serial, notBefore, notAfter, issuer, pubKeyInfo);
builder.addExtension(new Extension(Extension.basicConstraints, true, new DEROctetString(new BasicConstraints(true))));
X509CertificateHolder certHolder = builder.build(new JcaContentSignerBuilder(SIGNATURE_ALGORITHM).build(m_caKey.getPrivate()));
return new JcaX509CertificateConverter().getCertificate(certHolder);
}
}
内容来源于网络,如有侵权,请联系作者删除!