#!/usr/bin/env python3 from z3 import * C1=0x5D7E0D1F2E0F1F84 C2=0x388D76AEE8CB1500 C3=0xD2E9EE7E83C4285B inp, i1, i2, i3, i4, i5, i6, outp = BitVecs('inp i1 i2 i3 i4 i5 i6 outp', 64) s = Solver() s.add(i1==inp*C1) s.add(i2==RotateRight (i1, i1 & 0xF)) s.add(i3==i2 ^ C2) s.add(i4==RotateLeft(i3, i3 & 0xF)) s.add(i5==i4 + C3) s.add(outp==RotateLeft (i5, URem(i5, 60))) s.add(outp==10816636949158156260) # copypasted from http://stackoverflow.com/questions/11867611/z3py-checking-all-solutions-for-equation result=[] while True: if s.check() == sat: m = s.model() print (m[inp]) result.append(m) # Create a new constraint the blocks the current model block = [] for d in m: # d is a declaration if d.arity() > 0: raise Z3Exception("uninterpreted functions are not supported") # create a constant from declaration c=d() if is_array(c) or c.sort().kind() == Z3_UNINTERPRETED_SORT: raise Z3Exception("arrays and uninterpreted sorts are not supported") block.append(c != m[d]) s.add(Or(block)) else: print ("results total=",len(result)) break