我正在瀏覽Z3py,並對如何在特定情況下使用API有疑問。下面的代碼是我最終希望使用Z3的簡化版本。我的一些問題是: 1.有沒有辦法像下面的變量'a'一樣創建任意長度的數組值? 2.您可以通過Z3py訪問循環中的數組中的每個元素嗎? 3.是否可以將結果分配回原始變量或是需要新變量?轉換爲CNF會自動添加一個唯一的ID嗎? (即a + = b)學習Z3py - 是否支持數組和循環
總體而言,我迷失在如何將Z3py API應用於如下解決方案依賴於'b'的算法。感謝您的幫助或提示。
import sys
import struct
a = "\xff\x33\x01\x88\x02\x11\x03\x55"
b = sys.stdin.read(1) #a byte of user input - value 'a' is good
c = ''
d = ''
for x in range(len(a)):
c += struct.pack('B', int(a[x].encode('hex'), 16)^int(b.encode('hex'), 16))
print c.encode('hex')
second = '\x23\x23'
x = 0
while x < len(c):
d += struct.pack('h', int(c[x:x+1].encode('hex'), 16)^int(second.encode('hex'), 16))
x += 2
print d.encode('hex')
if d == '\xbd\x23\x43\x23\x40\x23\x41\x23':
print "Good"
else:
print "Bad"
我想檢查我是否理解這個問題。看來你想用Z3Py來解決這個問題:給定'a'和'd',找到'b',這樣你就可以打印出好的。是嗎? –
是的,這就對了。 – daybreak