Answers:
One approach to encode Factoring (RSA) to SAT is to use multiplicator circuits (Every circuit can be encoded as CNF).
.
The most naive encoding can be something like this: We know that
Then using Tseitin transformation, the above encoding can be translated into CNF.
This approach produces a relatively small CNF. But this encoding does not support "Unit Propagation" and so, the performance of SAT Solvers are really bad.
There are other circuit for multiplication which can be used for this purpose, but they produce a larger CNF.
Extending what @Amir wrote, I came across the following nice web page which hosts a CNF generator for factoring circuits that one could e.g. run on some of the (now inactive) RSA Factoring Challenge numbers. The generated instances are in DIMACS format that can directly be fed to any one of the current competitors in the annual SAT solver competition. Regarding hard SAT instances in general, the benchmark problems given at the SAT competition site appear to be quite useful, also the classification into random/crafted/industrial is nice.
Here's a paper on generating SAT instances from factoring:
Horie, S. & Watanabe, O. [1997] "Hard instance generation for SAT" Algorithms and Computation 1350:22-31 (pdf)
It's worse than linear, but better than . A 512-bit RSA challenge type number generates an instance with 63,652 variables and 406,860 clauses.
ToughSat by Henry Yuen and Joseph Bebel is another tool similar to the one linked by @Martin, which generates CNF formulas that encode instances of factoring and other hard problems.
See satfactor
:
Shane Neph
Determining factors of a large integer number has been of interest to Man since at least Euclid's time. There is no known general algorithm for this problem that scales in less than exponential time with respect to the number of bits needed to represent the integer.
Converts an integer factorization problem into a boolean SATISFIABILITY problem. If the problem is solved by a SAT solver, it then extracts the integer factors.
Boolen satisfiability solvers improve every year. Every 2 years, an international competition between solvers takes place (see http://www.satcompetition.org/ and http://www.satlive.org/). How well can these state-of-the-art solvers do against one of the oldest open math problems in existence?
This project has 2 main purposes:
1) Convert the problem and factor an integer of interest!
2) Quickly create either a solvable or an unsolvable SATISFIABILITY problem, whose difficulty is easily controlled by the creater.
- To create an unsolvable SATISFIABILITY problem, simply encode a prime number.
- To create more difficult but solvable problems, choose larger composite numbers with fewer factors.
The number of interest may be any size!
There are some open-source SATISFIABILITY solvers. See http://www.satlive.org/ for some of these.
make -C src/
Input a number of interest in its binary form:
bin/iencode 10101 > composite.21
// solve with your favorite solver and put results in solution.txt
bin/extract-sat composite.21 solution.txt
The output would be:
00011
00111
which are binary representations for decimal integers 3 and 7, the factors of 21.
If an input integer has more than 2 factors, and the SAT problem is solved, the output will be two of the factors only. These may not be prime numbers (you could test for that easily in Maxima, Maple, or Mathematica).
Not all SAT solvers output results in the same format. You may need to doctor those results slightly. extract-sat requires a solution file containing a list of integers (on any number of lines). For example,
1 -2 3 4 -5 ...