code: public static BigInteger join(List<SecretShare> shares) {
          if (!checkSamePrimes(shares)) {
              throw new IllegalArgumentException("shares not from the same series");
          }
          BigInteger res = BigInteger.ZERO;
          for (int i = 0; i < shares.size(); i++) {
              BigInteger n = BigInteger.ONE;
              BigInteger d = BigInteger.ONE;
              BigInteger prime = shares.get(i).getPrime();
              for (int j = 0; j < shares.size(); j++) {
                  if (i != j) {
                      BigInteger sp = BigInteger.valueOf(shares.get(i).getN());
                      BigInteger np = BigInteger.valueOf(shares.get(j).getN());
                      n = n.multiply(np.negate()).mod(prime);
                      d = d.multiply(sp.subtract(np)).mod(prime);
                  }
              }
              BigInteger v = shares.get(i).getShare();
              res = res.add(prime).add(v.multiply(n).multiply(d.modInverse(prime))).mod(prime);
          }
          return res;
      }
docs: Join shares back into the secret.
  
  @param shares to join
  @return secret number