You can use the Polard rho-algorithm for factorization. With all the improvements, it quickly suits numbers no less than 10 ^ 20.
Here is my implementation for factor search in Java:
public static BigInteger findFactor(BigInteger n) { final BigInteger result; if (n.isProbablePrime(80)) { result = n; } else { BigInteger gcd = n; BigInteger c = ONE; while (gcd.equals(n)) { int limitPower = 0; long k = 0; BigInteger y = ONE; boolean done = false; while (!done) { limitPower++; final long limit = Numbers.pow(2, limitPower); final int productLimit = (int) Numbers.pow(2, limitPower / 2); final BigInteger x = y; while (!done && k < limit) { final BigInteger savedY = y; int j = 0; final int jLimit = (int) Math.min(productLimit, limit - k); BigInteger p = ONE; while (j < jLimit) { y = next(n, c, y); p = p.multiply(x.subtract(y)).mod(n); j++; } gcd = Numbers.gcd(p, n); if (gcd.equals(ONE)) {
To divide numbers up to 10 14 you can also just do a trial division with odd numbers up to 10 7 .
source share