Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8988001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:55:26+00:00 2026-06-15T21:55:26+00:00

I’m going through Z3py and have a question with how to use the API

  • 0

I’m going through Z3py and have a question with how to use the API in a couple specific cases. The code below is a simplified version of something I would ultimately like to use Z3 for. Some of my questions are:
1. Is there a way to create an arbitrarily long array of values like the variable ‘a’ below?
2. Can you access each element of the array in loops through Z3py?
3. Is it possible to assign a result back into an original variable or is a new variable needed? Will the conversion to CNF automatically add a unique id? (ie a += b)

Overall, I’m lost on how to apply the Z3py API for something like the below algorithm where the solution depends on ‘b’. Any help or hints is/are appreciated, thank you.

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"
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T21:55:27+00:00Added an answer on June 15, 2026 at 9:55 pm

    We can accomplish that by writing a Python program that produces a Z3 expression. We use Python loops and lists (we can also use arrays) in this program, but these lists contain Z3 “symbolic” expressions instead of Python values. The resultant list d is a list of Z3 expressions containing b. Then, we ask Z3 to find a b such that elements of d are “equal” to the characters in the string '\xbd\x23\x43\x23\x40\x23\x41\x23'. Here is the code:

    from z3 import *
    
    def str2array(a):
        """
        Convert a string into a list of Z3 bit-vector values of size 8
        """
        return [ BitVecVal(int(a[x].encode('hex'), 16), 8) for x in range(len(a)) ]
    
    a = str2array("\xff\x33\x01\x88\x02\x11\x03\x55")
    # 'a' is a list of Z3 bitvector constants.
    print "a:", a
    # The elements of 'a' may look like Python integers but they are Z3 expressions.
    # We can use the method sexpr() to get these values in SMT 2.0 syntax.
    print [ a_i.sexpr() for a_i in a ]
    
    # b is a Z3 symbolic variable.
    b = BitVec('b', 8)
    
    # We compute a list 'c' of Z3 expressions from 'a' and 'b'.
    # We use Python list comprehensions but we can also use a for-loop.
    c = [ a_i ^ b for a_i in a ] 
    
    print "c:", c
    
    second = '\x23\x23'
    # We convert 'second' in a Z3 bit-vector value of size 16
    second = BitVecVal(int(second.encode('hex'), 16), 16)
    print "second:", second
    
    # The Z3 operation Concat concatenates two or more bit-vector expressions.
    d = []
    x = 0
    while x < len(c):
        # c[x] is a Bit-vector of size 8, second is a Bit-vector of size 16.
        # In Z3, we have to do the "casting" ourselves.
        # We use ZeroExt(8, c[x]) to convert c[x] into a Bit-vector of size 16,
        # by adding 0-bits.
        d.append(ZeroExt(8, c[x]) ^ second)
        x += 2
    print "d:", d
    
    goal = str2array('\xbd\x23\x43\x23\x40\x23\x41\x23')
    print "goal:", goal
    # Note that, len(goal) == 2*len(d)
    # We can use Concat to concatenate adjacent elements.
    
    # We want each element of d[i] == Concat(goal[2*i], goal[2*i+1])
    # We can use Z3 to find the 'b' that will satisfy these constraints
    
    s = Solver()
    # 's' is a Z3 solver object
    i = 0
    while i < len(d):
        s.add(d[i] == Concat(goal[2*i+1], goal[2*i]))
        i += 1
    print s
    # Now, 's' contains a set of equational constraints.
    print s.check()
    print s.model()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
This could be a duplicate question, but I have no idea what search terms
I don't have much knowledge about the IPv6 protocol, so sorry if the question
I am trying to loop through a bunch of documents I have to put
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.