Cryptography Reference
In-Depth Information
This returns a random number uniformly distributed on the interval [0, 2 numBits
1],
assuming a fair source of random bits is provided in rndSrc. Note that this constructor always
returns a nonnegative BigInteger. It throws an IllegalArgumentException if numBits < 0.
E XAMPLE . This constructor just generates random positive integers without regard to pri-
mality. Again, to ensure randomness which is hard to predict, SecureRandom objects should
be used, as seen here:
SecureRandom sr=new SecureRandom();
BigInteger p=new BigInteger(1024,sr);
2.6
METHODS
This is the last of the constructors; the BigInteger methods follow:
public static BigInteger valueOf(long val)
Returns a BigInteger with the specified value. This factory is provided in preference to
a (long) constructor because it allows for reuse of frequently used BigIntegers, such as 0 and
1, obviating the need for exported constants.
E XAMPLE .
(Note that this is a static method, and so is called by the class name):
final BigInteger ONE=BigInteger.valueOf(1);
The methods following perform basic arithmetic with BigIntegers.
public BigInteger add(BigInteger val) throws ArithmeticException
Returns a BigInteger whose value is ( this + val).
public BigInteger subtract(BigInteger val)
Returns a BigInteger whose value is ( this val).
public BigInteger multiply(BigInteger val)
Returns a BigInteger whose value is ( this · val).
public BigInteger divide(BigInteger val) throws ArithmeticException
Returns a BigInteger whose value is the quotient of ( this / val). It throws an ArithmeticEx-
ception if val = 0.
public BigInteger remainder(BigInteger val) throws
ArithmeticException
Returns a BigInteger whose value is the remainder of (
this
/ val). It throws an Arith-
meticException if val = 0.
Search WWH ::




Custom Search