Constraint Solvers
Lately, I’ve become interested in integer factorization and have been playing with constraint solvers. I started out with minion but quickly became frustrated. Minion does not support nesting of constraints or custom constraints from what I can tell. The set of equations I was working with were mostly comprised of terms that were either a*b mod 10 or (a*b – a*b mod 10) / 10. I would need to have all sorts of intermediate variables and constraints to express these terms. Which isn’t difficult, but would be tedious.
import sysfrom constraint import *p = Problem()p.addVariables([“x”, “y”], range(0, 999))p.addVariable(“z”, range(0, 999999))p.addConstraint(lambda x, y: x > 1 and y > 1, [“x”, “y”])p.addConstraint(lambda x, y, z: x * y == z, [“x”, “y”, “z”])p.addConstraint(lambda z: z == 123456, [“z”])print p.getSolution()
time ./bench.py{‘y’: 192, ‘x’: 643, ‘z’: 123456}real 17m16.996suser 17m11.200ssys 0m0.392s
MINION 3**VARIABLES**DISCRETE x {0..999}DISCRETE y {0..999}DISCRETE z {0..999999}**SEARCH**VARORDER [x, y]PRINT[[x, y, z]]**TUPLELIST****CONSTRAINTS**product(x, y, z)eq(z, 123456)sumgeq([x], 2)sumgeq([y], 2)**EOF**
Sol: 192 643 123456Solution Number: 1Time:0.000000Nodes: 2Solve Time: 0.208013Total Time: 0.276017Total System Time: 0.288018Total Wall Time: 0.651100Maximum Memory (kB): 0Total Nodes: 2Problem solvable?: yesSolutions Found: 1real 0m0.680suser 0m0.276ssys 0m0.312s
*** This is a Security Bloggers Network syndicated blog from Armchair Stratosphere authored by Jason. Read the original post at: http://maliciousattacker.blogspot.com/2010/12/constraint-solvers.html

