How to break the 2048bit BigInteger into words with a fixed number of 64 bits?
By : Alex Petrov
Date : March 29 2020, 07:55 AM
will be helpful for those in need I have a key that contain 2048 bit BigInteger number. I want to break it into words with a fixed number of 64 bits, and then computes the exclusive OR of all those words; does anyone can help me to implement this by java? this is my method that must be implemented: code :
LongBuffer buffer = ByteBuffer.wrap(myBigInteger.toByteArray()).asLongBuffer();
long xor = 0;
while (buffer.hasRemaining()) {
xor ^= buffer.get();
}
return BigInteger.valueOf(xor);

How to split the 2048 bits BigInteger into words with a fixed number of 64 bits?
By : Klawd Kompyuter
Date : March 29 2020, 07:55 AM
this will help If you want to use only BigIntegers in your method (instead of long), you can do it like that: code :
public static BigInteger parityWordChecksum(final BigInteger key) {
BigInteger result = new BigInteger("0");
BigInteger mask = BigInteger.ZERO;
for (int i = 0; i < 64; i++) {
mask = mask.setBit(i);
}
for (int i = 0; i < 2048; i += 64) {
result = result.xor(key.shiftRight(i).and(mask));
}
return result;
}

Calculating number of bits and number of words BigInteger
By : Jiri Kozel
Date : March 29 2020, 07:55 AM
I hope this helps . To represent decimal number of numDigits as binary number, it requires code :
numDigits * Math.log(10) / Math.log(2)
int numBits = (int)(((numDigits * bitsPerDigit[radix]) >>> 10) + 1);
Math.log(10) / Math.log(2) * Math.pow(2, 10) = 3401.6543691646593

Why Biginteger return non prime number and why less bits
By : Nidal HADDAD
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further I think you accidentally switched the parameters in exponent.modPow(randomServerPriemNumber, mod). a.modPow(b, c) evaluates to a^b mod c, not b^a mod c, but that shouldn't affect the result much, as all three numbers are 256bit length primes. As for the different bit lengths of the result, since the big length of BigInteger is the absolute minimum number of bits you would need to represent it, it differs for different values, even if they are modulo the same number. Take, e.g. "10 mod 10" and "7 mod 10". The first evaluates to 0, with a bit length of 0. The second evaluates to 7, with a bit length 3.

How can you specify a BigInteger with a maximum number of bits of type BigInteger?
By : SebB
Date : March 29 2020, 07:55 AM
With these it helps You can't. There is no constructor that takes a BigInteger number of bits. Why not? BigInteger doesn't store the number of bits internally as a big integer. It's holds an int number of bits, a design decision reflected in the public API: code :
BigInteger(int numBits, Random rnd);
int bitCount();
int bitLength();
static BigInteger probablePrime(int bitLength, Random rnd);

