Android Random Int Create generateSafePrimes(int size, int certainty, SecureRandom random)

Here you can find the source of generateSafePrimes(int size, int certainty, SecureRandom random)

Description

generate Safe Primes

License

LGPL

Declaration

static BigInteger[] generateSafePrimes(int size, int certainty,
            SecureRandom random) 

Method Source Code

//package com.java2s;
//License from project: LGPL 

import java.math.BigInteger;
import java.security.SecureRandom;

public class Main {
    private static final BigInteger ONE = BigInteger.valueOf(1);

    static BigInteger[] generateSafePrimes(int size, int certainty,
            SecureRandom random) {
        BigInteger p, q;//from  w ww. j  a  v a2s  .com
        int qLength = size - 1;

        for (;;) {
            q = new BigInteger(qLength, 2, random);

            // p <- 2q + 1
            p = q.shiftLeft(1).add(ONE);

            if (p.isProbablePrime(certainty)
                    && (certainty <= 2 || q.isProbablePrime(certainty))) {
                break;
            }
        }

        return new BigInteger[] { p, q };
    }
}

Related

  1. getRandomId()
  2. getRandomIntNum(int limit)
  3. getRandom(int from, int to)
  4. random(int min, int max)
  5. randomInt(int low, int high)