D
Dmitriy Melnik
Hello again,
Standard BigInteger class lacks several useful methods used in
cryptography such as square rooting and square rooting modulo a prime.
Of course, it is possible to create static methods like this and use
them:
public class NewMethods {
public static BigInteger sqrt(BigInteger n) { ... }
public static BigInteger modSqrt(BigInteger n, BigInteger modulo)
{ ... }
}
But this solution does not look elegant.
How can I enhance BigInteger in the way that'll provide consistent
interface? I tried to write something like this:
public class BigIntegerExt extends BigInteger {
// constructors are omitted
public BigIntegerExt sqrt() { ... }
public BigIntegerExt modSqrt(BigInteger modulo) { ... }
}
But this still seems to be inconsistent. A lot of inherited methods
still return a BigInteger. So I end up with the mess of two classes
and constant casting. For example:
BigIntegerExt a = new BigIntegerExt("1");
BigIntegerExt b = new BigIntegerExt("2");
BigIntegerExt c = a.sqrt(); // Works
BigIntegerExt d = a.add(b); // Doesn't work; needs explicit casting
from BigInteger to BigIntegerExt which is unsafe
Is there another way to transparently add several methods to
BigInteger?
Standard BigInteger class lacks several useful methods used in
cryptography such as square rooting and square rooting modulo a prime.
Of course, it is possible to create static methods like this and use
them:
public class NewMethods {
public static BigInteger sqrt(BigInteger n) { ... }
public static BigInteger modSqrt(BigInteger n, BigInteger modulo)
{ ... }
}
But this solution does not look elegant.
How can I enhance BigInteger in the way that'll provide consistent
interface? I tried to write something like this:
public class BigIntegerExt extends BigInteger {
// constructors are omitted
public BigIntegerExt sqrt() { ... }
public BigIntegerExt modSqrt(BigInteger modulo) { ... }
}
But this still seems to be inconsistent. A lot of inherited methods
still return a BigInteger. So I end up with the mess of two classes
and constant casting. For example:
BigIntegerExt a = new BigIntegerExt("1");
BigIntegerExt b = new BigIntegerExt("2");
BigIntegerExt c = a.sqrt(); // Works
BigIntegerExt d = a.add(b); // Doesn't work; needs explicit casting
from BigInteger to BigIntegerExt which is unsafe
Is there another way to transparently add several methods to
BigInteger?