Cryptography Reference
In-Depth Information
E XAMPLE .
This constructor is very useful when entering large integers in decimal format from
an input device. An example of how it may be called follows:
BigInteger m = new BigInteger( 92387569832653429874569286898623498 );
public BigInteger(String val, int radix) throws NumberFormatException
This translates a string containing an optional minus sign followed by a sequence of one
or more digits in the specified radix into a BigInteger. Any extraneous characters, includ-
ing whitespace, or a radix outside the range 2 through 36, will result in a NumberFormat-
Exception.
E XAMPLE .
This constructor is similar to the previous one, and is likewise very useful when
entering large integers in decimal format from an input device. However, with this con-
structor we can specify the base of the number being entered. An example of creating a Big-
Integer object from the string representation of a number in base 2 follows:
BigInteger m = new
BigInteger( 101111100001010111010000001111101010011111101 ,2);
public BigInteger(int bitLength, int certainty, Random rnd)
This returns a randomly selected BigInteger with the specified bitLength that is proba-
bly prime. The certainty parameter is a measure of the uncertainty that the caller is willing
to tolerate: the probability that the number is prime will exceed 1
= certainty.
The execution time is proportional to the value of the certainty parameter. The given ran-
dom number generator is used to select candidates to be tested for primality. This will throw
an ArithmeticException if bitLength < 2.
(1/2) t where
t
E XAMPLE .
This BigInteger constructor will prove to be the most useful of them all for our
purposes, for it can generate random (probable) primes for use in cryptosystems. To gener-
ate an integer 1024 bits long, which is prime with probability 0.875 = 1 (0.5) 3 , we could
make the following calls:
SecureRandom sr=new SecureRandom();
BigInteger p=new BigInteger(1024,3,sr);
The SecureRandom class (seen here) is a subclass of Random; if used properly, it gen-
erates random integers much more difficult to predict than those created by ordinary ran-
dom number generators.
public BigInteger(int numBits, Random rndSrc) throws
IllegalArgumentException
Search WWH ::




Custom Search