def generateBP(self): """Transform UC to BP. Call UC generation if UC not present.""" if self.uc is None: self.generateUC() logging.info('Starting BP generation') self.bp = BranchingProgram.fromCircuit(self.uc) logging.info('BP generation successful')
def setUp(self): self.inputLength = 2 outputLength = 1 numberOfGates = 2 inputs = [Input("x"+str(x)) for x in range(0, self.inputLength)] # (-(x0 & x1) & (-x2 & x3)) & ((x4 & x5) & -(x6 & -x7)) self.circuit = Circuit(NotGate(AndGate(inputs[0], inputs[1]))) uc = UniversalCircuit(self.inputLength, outputLength, numberOfGates) bp = BranchingProgram.fromCircuit(uc) self.fixedBP = fixBP(bp, self.circuit)
def setUp(self): self.inputLength = 2 outputLength = 1 numberOfGates = 2 inputs = [Input("x" + str(x)) for x in range(0, self.inputLength)] # (-(x0 & x1) & (-x2 & x3)) & ((x4 & x5) & -(x6 & -x7)) self.circuit = Circuit(NotGate(AndGate(inputs[0], inputs[1]))) uc = UniversalCircuit(self.inputLength, outputLength, numberOfGates) bp = BranchingProgram.fromCircuit(uc) self.fixedBP = fixBP(bp, self.circuit)
assert(len(newIndex)==len(newIns0)) return (newIns0, newIns1, newIndex) if __name__ == '__main__': from obfusc8.circuit import Circuit, Input, AndGate, NotGate from itertools import product inputLength = 2 outputLength = 1 numberOfGates = 2 inputs = [Input("x"+str(x)) for x in range(0, inputLength)] # (-(x0 & x1) & (-x2 & x3)) & ((x4 & x5) & -(x6 & -x7)) circuit = Circuit(NotGate(AndGate(inputs[0], inputs[1]))) print circuit uc = UniversalCircuit(inputLength, outputLength, numberOfGates) print uc bp = BranchingProgram.fromCircuit(uc) print bp fixedBP = fixBP(bp, circuit) print 'After fixing: %s'%fixedBP for test in list(product([0,1], repeat=inputLength)): test = list(test) circuitResult = circuit.evaluate(test) bpResult = fixedBP.evaluate(test) print('Input: %s => circuit: %d, fixedBP: %d, equal?: %s'%(test, circuitResult, bpResult, circuitResult==bpResult))
def fromCircuit(cls, circuit, p, rndMatSize=None): """Create a RBP directly with a circuit input""" return cls(BranchingProgram.fromCircuit(circuit), p, rndMatSize)