Post
Topic
Board Development & Technical Discussion
Re: Using Kangaroo for WIF solving
by
NotATether
on 09/02/2021, 16:08:42 UTC
Just a lazy solution:
Code:
import java.math.BigInteger;

public class K {
    public static void main(String[] args) {
        BigInteger start = new BigInteger("0552e025571c01bcd9eda59365a2fb3ae0bd7547dfeeeb13d971d848bcbf0467", 16);
        BigInteger stride = BigInteger.valueOf(58L).pow(32);//depends on the position of most-right unknown character
        BigInteger range = BigInteger.valueOf(58L).pow(5);//5=number of unknown characters
        BigInteger end = start.add(range);
        System.out.println("START: "+start.toString(16));
        System.out.println("END: "+end.toString(16));
        System.out.println("STRIDE: "+stride.toString(16));
    }
}

This can be extended to handle a "partial" number of characters known, which is the case where some of the bits are set, by changing 5 to be a decimal number. For example by setting it to 4.5 we can do the equivalent of searching for 4 characters plus the the first 29 base58 values 1-V of the fifth. Or the first character having the last 29 base58 values W-z and 4 whole characters after that (or anything between those two).

This will make Kangaroo perform better in the cases where you know one of the characters is in a range but searching all 58 characters is too prohibitive, like when you're already searching a lot of characters.

Although doing a fractional exponentiation on a BigInteger is going to be a problem. Ideally you do not want to change this to BigDecimal for performance reasons, and you can't split the decimal into a fraction and do 58^num / 58^denom = 58^num * 58^-denom because BigInteger.pow() raises an exception with a negative exponent. Worst case scenario is that you use the divide(58^denom) method but I have no idea how slow dividing BigInts together is going to be. (Maybe try 58^num * (58^denom).modInverse(m) but set the modulus m to something bigger than 58^denom so we don't do the "mod" part of modInverse. But this only brings benefit if modInverse() is faster than the divide() method.

This can easily be ported to other languages provided that their math libraries are sane and let you take negative exponents (unlike Java). In particular it's a very useful feature to port to the original Kangaroo itself if Jean_Luc is still around on Github.