I'm trying to find a key that fulfills these conditions:
- Key length is 19 characters
- Characters in the ASCII range are from 0x30 to 0x5F
- Key[1] same as key[2]
- Summary of all characters is 1418 (decimal)
- Summary of sum_mul_pi function is 39944 (decimal)
- ... redacted for simplicity
My problem is with float operations in Z3. I cannot write correct expressions in Z3 because z3 returns nothing.
If I remove the sum_mul_pi function (float operations), I get a lot of results and I process those results using non-z3 (python only) code to filter out those that don't match this condition, I see some results.
Why those results are not written by z3 with the sum_mul_pi function?
Thanks!
#
# this is a simplified model, there are more constraints
#
from z3 import *
set_param("parallel.enable", True)
def sum_mul_pi(values):
val = BitVecVal(0, 64)
for i in range(0, len(values)):
val1 = FPVal(float(i) * float(3.141592), Float(64))
val2 = fpMul(RTZ(), fpBVToFP(values[i], Float64()), val1)
val += fptoUBV(RTZ(), val2, BitVecSort(64))
return val
key = [BitVec("i%d" % i, 64) for i in range(19)]
s = Solver()
for x in range(19):
s.add(key[x] >= ord("0"))
s.add(key[x] <= ord("_"))
s.add(key[1] == key[2])
s.add(Sum(key) == 1418)
s.add(sum_mul_pi(key) == 39944)
while s.check() == sat:
m = s.model()
ss = "".join([chr(m[x].as_long()) for x in key])
print(ss)
s.add(Or([ f() != m[f] for f in m.decls() if f.arity() == 0]))
sum_mul_pi is really not complicated, python only version looks like this:
def sum_mul_pi(values):
val = 0
for i in range(0, len(values)):
val1 = float(i) * float(3.141592)
val2 = float(ord(values[i])) * val1
val += int(val2)
return val