|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectds.ov2.util.BigIntUtil
public class BigIntUtil
BigInteger
Utilities. Extending the BigInteger
class for these few methods is not an option because one would need
to program downcasts for all methods that return a fresh BigInteger
, which are basically all methods of BigInteger
.
Static class.
Constructor Summary | |
---|---|
protected |
BigIntUtil()
Static class, object creation disabled. |
Method Summary | |
---|---|
static int |
byte_size(BigInteger bi)
BigInteger size in bytes. |
static boolean |
coprime(BigInteger a,
BigInteger b)
Coprime check. |
static void |
copy_into_byte_array(BigInteger bi,
byte[] a)
Copy a BigInteger into a byte array. |
static BigInteger |
from_byte_array(byte[] a)
Convert a byte array into a BigInteger . |
static BigInteger |
mod_rand_with_inverse(Random rand,
BigInteger mod)
Modular random number generator for the multiplicative subgroup. |
static BigInteger |
mod_rand(Random rand,
BigInteger mod)
Modular random number generator. |
static BigInteger |
multi_exponent(BigInteger[] base,
BigInteger[] exponent,
BigInteger modulus)
Compute the multi-exponent base^exponent (modulo
modulus) . |
static void |
print_array(PrintWriter out,
String intro_format,
String line_start,
BigInteger[] bi)
Prints a BigInteger array as follows. |
static String |
to_byte_hex_string(BigInteger bi)
Converts a BigInteger into a hex string. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
protected BigIntUtil()
Method Detail |
---|
public static boolean coprime(BigInteger a, BigInteger b)
a
- first BigIntegerb
- second BigInteger
a
and b
are coprime.public static BigInteger mod_rand(Random rand, BigInteger mod)
mod
with a bit
length at most 4 less than the bit length of mod
.
rand
- Random number generatormod
- modulus
mod
public static BigInteger mod_rand_with_inverse(Random rand, BigInteger mod)
mod
that has a modular inverse modulo mod
.
The bit length of the random number is at most 4 less than
mod
.
rand
- Random number generatormod
- modulus
mod
with a modular
inversepublic static BigInteger multi_exponent(BigInteger[] base, BigInteger[] exponent, BigInteger modulus)
base^exponent (modulo
modulus)
.
Asserts that the base
and exponent
array have
the same length.
base
- the basesexponent
- the exponentsmodulus
-
base[0]^exponent[0] *
base[1]^exponent[1] * ... (modulo modulus)
public static int byte_size(BigInteger bi)
BigInteger.ZERO
it returns 1.
Note that the value computed here might be different
from
BigInteger.toByteArray
.length
because the latter might add a leading zero byte.
bi
-
bi
public static String to_byte_hex_string(BigInteger bi)
BigInteger
into a hex string. In contrast to
BigInteger.toString(16)
4-digit-groups are separated by points, like 23EA.4F11...
bi
- BigInteger to convert
public static void copy_into_byte_array(BigInteger bi, byte[] a)
BigInteger.toByteArray()
.
First, the argument array a
might need some zero
padding and second, BigInteger.toByteArray()
might have a
leading zero that does not fit into a
.
Asserts that the BigInteger bi
, with leading zeros
removed, fits into a
.
bi
- the source BigIntegera
- the destination arraypublic static BigInteger from_byte_array(byte[] a)
BigInteger
. This is just as
BigInteger.BigInteger(byte[])
but does not produce
negative BigIntegers if the first bit in a
is set.
a
- source byte array
a
public static void print_array(PrintWriter out, String intro_format, String line_start, BigInteger[] bi)
BigInteger
array as follows.
4 bases base[0]: 5F11.9615 = 1594988053 base[1]: 1999.3BC3 = 429472707 base[2]: 00.8327.3245 = 2200384069 base[3]: 5D9E.AA9A = 1570679450The first line is hex, the second decimal.
Argument intro_format
must be a format string that
accepts the length of the array as integer argument. It is used
for the heading. In the above example it is "%d bases\n". Note
the newline at the end!
The line_start
is a string with the name of the array,
in the above example it is "base".
out
- output channelintro_format
- format string with at most integer directive
for the headingline_start
- name of the arraybi
- the array to print
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |