我有一个程序,该程序具有以下伪代码中所述的逻辑。 x
是一个字符串,x[k]
将返回索引k
处字符的十进制字符。 ^
运算符返回操作数的十进制XOR结果。
x = input
int checksum = x[0] ^ x[1] ^ x[2]
int sum = 0
sum += x[36] ^ x[23] == 111
sum += x[23] ^ x[29] == 101
sum += x[29] ^ x[30] == 116
sum += x[30] ^ x[9] == 115
sum += x[9] ^ x[25] == 0
return sum == checksum and x[0] ^ x[29] == 100 and x[1] ^ x[30] == 200
我想找到使该程序返回true
的输入。如果我想在Z3Py中解决此问题,有什么办法可以解决?我需要N个约束中的K个,以便我可以将约束表达为表达式,但是我没有找到对此的支持。
我想对Z3做的伪代码:
int checksum = x[0] ^ x[1] ^ x[2]
bools = []
bools.append(Bool(x[36] ^ x[23] == 111))
bools.append(Bool(x[23] ^ x[29] == 101))
bools.append(Bool(x[29] ^ x[30] == 116))
bools.append(Bool(x[30] ^ x[9] == 115))
bools.append(Bool(x[9] ^ x[25] == 0))
state.add(bools[0])
state.add(bools[1])
state.add(bools[2])
state.add(bools[3])
state.add(bools[4])
state.add(x[0] ^ x[29] == 100)
state.add(x[1] ^ x[30] == 200)
state.add(PbEq([boolean for boolean in bools], checksum))