简体   繁体   中英

Z3py - do a roll

Is there a recommended way of doing a bitwise roll to either left or right by any amount?

For example with a byte - 0x57 rolr 3 = 0xEA .

I have not found any "roll" operation in the Z3py docs. I was thinking about using a BitVec s for each bit but that doesn't seem efficient/probably won't work. Any advice is appreciated, thanks.

Edit: Thanks for the answers so far. This is more of an API question because I suck at it right now. Heres what I have as a starting point.

def roll(bt):
count = BitVecVal(int('0x03', 16), 8)
s.add(bt == (bt << count | bt >> (8 - count)) & 0xFF)

a = BitVec('a', 8)
s = Solver()
roll(a)
s.add(a == BitVecVal(int('0xEA', 16), 8))
s.check()

This prints out nothing and model is not available.

You can do a rotate like this:

size = 0x100  # size of the bitvector

rotated = (x << n) | (x >> (size - n)) & (size - 1)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM