An architectural constraint-satisfaction approach to integer factorization. Instead of algebraic division, this algorithm treats semiprime decomposition as a deterministic cascade—reconstructing prime factors digit-by-digit from the least significant column leftward using positional modulus pruning, terminal digit determinism, and square-root depth bounding.
Eliminates manual carry-over tracking via positional modular arithmetic.
Terminal digit determinism reduces 100 initial pairs down to 2 or 3 valid seeds.
Locks DFS tree recursion depth to the geometric center around √N.
Evolved from a 20-year-old Java array prototype to C++ Boost BigInt DFS.
The security of the RSA cryptosystem relies on the computational asymmetry of multiplying two large primes (p × q = N). While classical algorithms like the General Number Field Sieve (GNFS) treat N as a monolithic algebraic entity, this research approaches factorization from a low-level hardware mindset—treating multiplication as a deterministic cascade of single-digit operations.
Originally conceived over two decades ago in an experimental Java solver inspired by assembly-level shift-and-add Arithmetic Logic Units (ALUs), the early build stalled on the state-management complexity of rigid 3D arrays. By modernizing the architecture into an implicit 10-ary Depth-First Search (DFS) tree with arbitrary-precision integers, the call stack handles state rollback automatically.
In base-10 arithmetic, any digit added at position k or higher is a multiple of 10ᵏ. Therefore, the rightmost k digits of a product depend exclusively on the rightmost k digits of its factors. If a partial candidate pair fails the local modulus check, no digits added to the left can ever repair it—allowing immediate branch pruning.
Test the algorithm directly in your browser. Select a semiprime preset or enter a custom semiprime ending in 1, 3, 7, or 9 to observe how Terminal Digit Determinism, Positional Modulus Pruning, and the Square Root Bound collapse the search space.
While base-10 tree branching still scales exponentially at 2048-bit cryptographic scales, combining three structural constraints drastically collapses the search space compared to naive trial division and unpruned trees.
Comparing Naive Trial Division, Unpruned 10-ary Tree, and Optimized RTL-DFS.
Percentage of theoretical 100-branch expansions surviving (A×B) mod 10ᵏ ≡ N mod 10ᵏ.
Any prime factor greater than 5 must end in 1, 3, 7, or 9. Consequently, N mod 10 deterministically locks the one's place into just 2 or 3 seed pairs, amputating Depth 0 entirely.
| Target N mod 10 | Viable Seed Pairs (p₀, q₀) | Search Reduction |
|---|---|---|
| Ends in 1 | (1, 1), (3, 7), (9, 9) | 97.0% pruned |
| Ends in 3 | (1, 3), (7, 9) | 98.0% pruned |
| Ends in 7 | (1, 7), (3, 9) | 98.0% pruned |
| Ends in 9 | (1, 9), (3, 3), (7, 7) | 97.0% pruned |
To prevent trivial trial division, RSA standards mandate that primes p and q share equal bit-lengths—clustering both factors tightly around √N. For a 5-digit target like 45,113 (√45113 ≈ 212.4), factors 197 and 229 sit directly on the median boundary.
Access the complete C++ arbitrary-precision constraint solver (Boost.Multiprecision), the legacy Java historical prototype, the white paper Markdown, and the multiprocessing semiprime dataset generator.
// Compile: g++ -O3 factor.cpp -o factor (Requires libboost-all-dev)
#include <iostream>
#include <string>
#include <vector>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
using namespace boost::multiprecision;
const cpp_int TARGET("45113");
bool solution_found = false;
cpp_int pow10_big(int exp) {
cpp_int res = 1;
for (int i = 0; i < exp; ++i) res *= 10;
return res;
}
// Recursive 10-ary DFS with Positional Modulus Pruning & Square Root Bound
void find_factors(int depth, cpp_int partial_A, cpp_int partial_B) {
if (solution_found) return;
if (partial_A * partial_B == TARGET && partial_A != 1 && partial_B != 1) {
cout << "\n[+] Prime Factors Found: " << partial_A << " and " << partial_B << endl;
solution_found = true;
return;
}
// Square Root Bound: Lock depth to half the base-10 length of N
int max_depth = TARGET.str().length() / 2;
if (depth > max_depth) return;
cpp_int current_mod = pow10_big(depth + 1);
cpp_int pos_mult = pow10_big(depth);
for (int a = 0; a <= 9; ++a) {
for (int b = 0; b <= 9; ++b) {
cpp_int candidate_A = partial_A + (a * pos_mult);
cpp_int candidate_B = partial_B + (b * pos_mult);
// Modulus Pruning: Abandon branch immediately if rightmost k digits mismatch
if ((candidate_A * candidate_B) % current_mod == TARGET % current_mod) {
find_factors(depth + 1, candidate_A, candidate_B);
}
}
}
}
int main() {
int terminal_digit = (int)(TARGET % 10);
vector<pair<int, int>> seed_pairs;
// Terminal Digit Determinism: Amputate Depth 0 completely
if (terminal_digit == 1) seed_pairs = {{1, 1}, {3, 7}, {9, 9}};
else if (terminal_digit == 3) seed_pairs = {{1, 3}, {7, 9}};
else if (terminal_digit == 7) seed_pairs = {{1, 7}, {3, 9}};
else if (terminal_digit == 9) seed_pairs = {{1, 9}, {3, 3}, {7, 7}};
for (auto& p : seed_pairs) {
if (solution_found) break;
find_factors(1, p.first, p.second); // Launch directly at ten's column
}
return 0;
}
# Future Work Phase 2: Multiprocessing Semiprime Feature Extractor for PyTorch
import multiprocessing as mp
import pandas as pd
from Crypto.Util.number import getPrime
from collections import Counter
import os
NUM_SAMPLES = 100_000
BIT_LENGTH = 128
CHUNK_SIZE = 1000
def generate_semiprime_batch(batch_size):
records = []
prime_bits = BIT_LENGTH // 2 # Enforce Square Root Bound
while len(records) < batch_size:
p, q = getPrime(prime_bits), getPrime(prime_bits)
if p > q:
p, q = q, p # Symmetry Breaking (p <= q)
n = p * q
str_n = str(n)
counts = Counter(str_n)
freq_vec = [counts.get(str(i), 0) for i in range(10)]
records.append({
'n_length': len(str_n),
'terminal_n': int(str_n[-1]),
'terminal_p': int(str(p)[-1]),
'terminal_q': int(str(q)[-1]),
**{f'freq_{i}': freq_vec[i] for i in range(10)},
'n_val': str_n, 'p_val': str(p), 'q_val': str(q)
})
return records
if __name__ == '__main__':
batches = [CHUNK_SIZE] * (NUM_SAMPLES // CHUNK_SIZE)
with mp.Pool(processes=os.cpu_count()) as pool:
data = [item for sub in pool.map(generate_semiprime_batch, batches) for item in sub]
df = pd.DataFrame(data)
df.to_parquet(f"rsa_dataset_{BIT_LENGTH}bit.parquet", engine='pyarrow', compression='snappy')
Pure neural networks fail at direct RSA factorization due to the avalanche effect of modular arithmetic—there is no smooth gradient when guessing a prime factor. However, pairing statistical machine learning with rigid mathematical verification unlocks powerful hybrid architectures.
Instead of evaluating digit pairs (a, b) sequentially from 0 to 9, a lightweight Multi-Layer Perceptron (MLP) trained on digit frequency distributions scores candidate branches at each column depth. The C++ solver queries the model via PyBind11 to traverse highest-probability paths first while retaining exact modulus pruning.
Constructing multi-million sample datasets of balanced semiprimes tagged with their terminal digit seed classes and base-10 frequency vectors. Using native arbitrary-precision CPU multiprocessing avoids GPU PCIe serialization bottlenecks, exporting compressed .parquet files directly for GPU neural network training.
Asymmetrical backtracking causes severe warp divergence on SIMT GPU architectures, while dynamic BigInt allocations trigger VRAM register spilling. Future architecture experiments explore a hybrid pipeline: expanding a Breadth-First Search on host CPU cores to depth K, then dispatching fixed-width 64-bit limb registers across GPU wavefronts.
Deploying multi-agent neuro-symbolic workflows pairing LLM hypothesis generation with Computer Algebra Systems (SageMath, PARI/GP, FLINT). Agents automatically benchmark positional modulus pruning against Coppersmith's lattice reduction and Fermat's method to evaluate asymptotic bounds (O-complexity) across bit-lengths.