示例#1
0
 def __init__(self, world):
     self.world = world
     self.prover = Prover()
     self.wumpus = None
     self.pits = set()
     self.safe = {self.position}
     self.unsafe = defaultdict(set)
     self.visited = [self.position]
示例#2
0
def build_prover(search_method, printsearch):
    search_obj = None
    if (search_method == 'dfs'):
        search_obj = DFSSearch()
    if (search_method == 'nn'):
        search_obj = NeuralNetworkSearch() 
    prover = Prover(search_obj)
    prover.print = printsearch
    return prover
    def setUp(self):
        n = 10

        crs = CRS(n)
        s_randoms = make_s_randoms(n, crs.order)
        sigma = random_permutation(n)
        ciphertexts = encrypt_messages(crs.order, crs.pk1, crs.pk2,
                                       list(range(n)))
        prover = Prover(crs)
        self.proof = prover.prove(n, ciphertexts, sigma, s_randoms)
        self.crs = crs
        self.ciphertexts = ciphertexts
示例#4
0
    def __init__(self, id, binDir, selection = None, main_alg = None, binName = 'vampire'):
        Prover.__init__(self,id)
        self.__binLocation = '%s/%s' % (binDir, binName)
        if selection:
	  self.__selection = ["--selection", str(selection)]
	else:
	  self.__selection = []

	if main_alg:
	  self.__main_alg = ["--main_alg", main_alg]
	else:
	  self.__main_alg = []
示例#5
0
    def createEmptySpaces(self,num):
        removed = []
        while num > 0 and len(removed) < 81:
            row = random.randint(0,8)
            col = random.randint(0,8)
            prover = Prover(self)

            if(prover.isRemoveValid(row,col)):
                self.wholeBoard[row][col] = 0
                num -=1

            removed.append((row,col))
        return num
示例#6
0
    def verify(self, ciphertexts, proof):
        prover = Prover(self.crs)

        A1, A2 = self.step1(prover, proof['A1'], proof['A2'])
        p1, p2, p3, p4 = self.step2()
        perm_ok = self.step3(prover, A1, A2, p1, proof['pi_1sp'])
        valid = self.step4(prover, p2, p3, proof['pi_c2_1'],\
                proof['pi_c2_2'], proof['shuffled_ciphertexts'])
        R = self.step5(prover, proof['pi_c1_1'], proof['pi_c1_2'],
                       proof['pi_c2_1'], p4)
        consistent = self.step6(prover, ciphertexts,\
                proof['shuffled_ciphertexts'], A2, p4, R)
        return perm_ok, valid, consistent
示例#7
0
文件: alg.py 项目: ruricolist/dig
    def __init__(self, filename):
        assert os.path.isfile(filename), filename

        import tempfile
        tmpdir = tempfile.mkdtemp(dir=settings.tmpdir, prefix="DIG2_")
        basename = os.path.basename(filename)
        src = os.path.join(tmpdir, basename)
        _, rs_err = CM.vcmd("astyle -Y < {} > {}".format(filename, src))
        assert not rs_err, rs_err
        logger.debug("src: {}".format(src))
        src = Src(src)
        self.inpdecls, self.invdecls = src.parse()
        printfSrc = src.instrPrintfs(self.invdecls)
        exeFile = "{}.exe".format(printfSrc)
        cmd = "gcc -lm {} -o {}".format(printfSrc, exeFile)  #-lm for math.h
        CM.vcmd(cmd)
        tcsFile = "{}.tcs".format(printfSrc)  #tracefile

        self.prover = Prover(src, self.inpdecls, self.invdecls, tmpdir)
        self.tmpdir = tmpdir
        self.filename = filename
        self.tcsFile = tcsFile
        self.exeFile = exeFile
        logger.info("analyze {}".format(filename))
示例#8
0
 def __init__(self, id, sorts, binDir, binName = 'spass'):
     Prover.__init__(self,id)
     self.__binLocation = '/home/marcio/GridTest/bin/spass'
     self.__sortsParam  = sorts  # default is 1, but layered translation seems to work better with 0
示例#9
0
 def __init__(self, id, binDir, binName = 'convRacer'):
     Prover.__init__(self,id)
     self.__binLocation = '%s/%s' % (binDir, binName)
import sys
from prover import Prover
from device import RealDevice

if __name__ == '__main__':
    if len(sys.argv >= 1):
        server_url = sys.argv[1]
    else:
        server_url = 'http://localhost:5000'
    device_id = sys.argv[2]
    inport = sys.argv[3]
    outport = sys.argv[4]
    device = RealDevice(inport, outport)
    prover = Prover(device, server_url)
    prover.register()
示例#11
0
 def __init__(self, id, binDir, binName = 'hyloban', topo = '--t0'):
     Prover.__init__(self, id)
     self.binLocation = '%s/%s' % (binDir, binName)
     self.topo        = topo
示例#12
0
 def __init__(self,id,binDir,binName='haksat'):
     Prover.__init__(self,id)
     self.binLocation = '%s/%s' % (binDir, binName)
示例#13
0
 def __init__(self, id, binDir, binName = 'spartacus', extraArgs=''):
     Prover.__init__(self, id)
     self.binLocation = '%s/%s' % (binDir, binName)
     self.extraArgs   = extraArgs.split()
示例#14
0
 def addNewStatsToBatch(self, batch):
     proverStats = self.prover.addNewStatsToBatch(batch)
     myStats = Prover.addNewStatsToBatch(self,batch)
     myStats.aliasWith(proverStats)
     return myStats
import sys
from database import database
from prover import Prover

if __name__ == '__main__':
    if len(sys.argv >= 1):
        device_id = sys.argv[1]
    else:
        print('No device id provided')

    if len(sys.argv >= 2):
        server_url = sys.argv[2]
    else:
        server_url = 'http://localhost:5000'

    device = database.get(device_id)
    if not device:
        print('No device with id {0} found in the database'.format(device_id))

    prover = Prover(device, server_url)

    prover.authenticate()
示例#16
0
 def __init__(self, id, binDir, binName = 'htab', extraArgs='--allreflexive', translation=None):
   Prover.__init__(self, id)
   self.binLocation = '%s/%s' % (binDir, binName)
   self.statsStr    = ':0:c'
   self.extraArgs   = extraArgs.split()
   self.translation = translation
示例#17
0
class Agent(object):
    def __init__(self, world):
        self.world = world
        self.prover = Prover()
        self.wumpus = None
        self.pits = set()
        self.safe = {self.position}
        self.unsafe = defaultdict(set)
        self.visited = [self.position]

    @property
    def position(self):
        return self.world.agent

    def inspect_position(self):
        if self.world.agent_on_stench():
            self.found_stench()
        else:
            self.no_stench()

        if self.world.agent_on_breeze():
            self.found_breeze()
        else:
            self.no_breeze()

        if self.world.agent_on_gold():
            self.found_gold()

        self.search_for_wumpus()
        self.search_for_pit()

    def search_for_wumpus(self):
        adjacent_hidden_cells = self.get_adjacent_hidden_cells()
        if self.wumpus is not None or not adjacent_hidden_cells:
            return
        print "Agent is searching for Wumpus"
        for cell in adjacent_hidden_cells:
            if self.prover.check_wumpus(*cell):
                print "!Agent deduced Wumpus at", cell
                self.wumpus = cell
                self.prover.add_wumpus(*cell)
                return
        print "Agent did not find Wumpus"

    def found_stench(self):
        print "!Agent found a stench"
        self.prover.add_stench(*self.position)

    def no_stench(self):
        self.prover.add_no_stench(*self.position)

    def search_for_pit(self):
        adjacent_hidden_cells = self.get_adjacent_hidden_cells()
        if not adjacent_hidden_cells:
            return
        print "Agent is searching for pit"
        for cell in adjacent_hidden_cells:
            if self.prover.check_pit(*cell):
                print "!Agent deduced pit at", cell
                self.pits.add(cell)
                self.prover.add_pit(*cell)
                return
        print "Agent did not find pit"

    def found_breeze(self):
        print "!Agent found a breeze"
        self.prover.add_breeze(*self.position)

    def no_breeze(self):
        self.prover.add_no_breeze(*self.position)

    def found_gold(self):
        print "!Agent found gold!"
        print "Agent is picking up gold"
        self.world.pickup_gold()
        if self.found_all_gold():
            print "!Agent found all the gold! Hooray!"
            self.leave_world()

    def found_all_gold(self):
        return self.world.num_gold == 0

    def make_move(self):
        self.inspect_position()

        print "Agent is checking adjacent hidden cells"
        cell = self.get_adjacent_safe_hidden_cell()
        if cell is not None:
            print "Agent found safe hidden cell", cell
            return self.travel_to(cell)
        print "Agent could not find safe hidden cell"

        print "Agent is re-checking visited cells"
        for cell in reversed(self.visited[:-1]):
            print "Agent is checking", cell
            cell2 = self.get_adjacent_safe_hidden_cell(cell)
            if cell2 is not None:
                print "Agent found safe hidden cell", cell2
                return self.travel_to(cell2)

        print "!Agent can't find a move!"
        self.leave_world()

    def leave_world(self):
        print "Agent is heading to goal"
        self.travel_to(self.world.goal)
        if self.position != self.world.goal:
            print "!Agent cannot find his way to goal!"
            print "!Agent is giving up, doomed to forever wander aimlessly through the destitute labyrinth of the Wumpus world. If only his logic had been better! If only his creator had added more rules!"
            quit()
        print "!Agent is exiting the Wumpus world"
        self.world.exit()

    def travel_to(self, cell):
        if cell not in self.get_adjacent_cells():
            print "Agent is traveling to cell", cell
            path = self.get_path_to_cell(cell)
            print "Agent found safe path to cell", cell, "->", path
        else:
            path = [cell]
        if path:
            for cell in path:
                self.world.move_agent(cell)
                print "!Agent moved to cell", cell
                self.visited.append(cell)

    def is_safe(self, cell):
        print "Checking safety of", cell
        if cell in self.safe:
            print cell, "was already determined to be safe"
            return True
        if cell in self.unsafe[self.world.time]:
            print cell, "was already determined to be unsafe at time", self.world.time
            return False

        if cell == self.wumpus:
            safe = False
        elif cell in self.pits:
            safe = False
        else:
            safe = self.prover.check_safe(*cell)

        if safe:
            print cell, "is safe"
            self.safe.add(cell)
        else:
            print cell, "is not safe at time", self.world.time
            self.unsafe[self.world.time].add(cell)

        return safe

    def is_hidden(self, cell):
        return cell not in self.world.visible_cells

    def is_visible(self, cell):
        return not self.is_hidden(cell)

    def get_adjacent_safe_hidden_cell(self, start=None):
        for cell in self.get_adjacent_hidden_cells(start):
            if self.is_safe(cell):
                return cell

    def get_adjacent_hidden_cells(self, cell=None):
        return set(filter(self.is_hidden, self.get_adjacent_cells(cell)))

    def get_adjacent_visible_cells(self, cell=None):
        return set(filter(self.is_visible, self.get_adjacent_cells(cell)))

    def get_adjacent_cells(self, cell=None):
        if cell is None:
            cell = self.position
        x, y = cell
        adjacent_cells = [
            (x - 1, y),
            (x + 1, y),
            (x, y - 1),
            (x, y + 1),
        ]

        return set(filter(self.world.in_bounds, adjacent_cells))

    def get_path_to_cell(self, dest):
        print "Agent is searching for safe path to cell", dest
        checked_cells = set()
        path_cells = {self.position}
        paths = []

        if self.is_visible(dest):
            dest_check = self.get_adjacent_visible_cells
        else:
            dest_check = self.get_adjacent_hidden_cells

        for cell in dest_check():
            if cell == dest:
                return [cell]

        checked_cells.add(self.position)

        for cell in self.get_adjacent_visible_cells():
            path = [cell]
            paths.append(path)
            path_cells.add(cell)

        while len(checked_cells) < len(self.world.visible_cells):
            new_paths = []
            for path in paths:
                last_cell = path[-1]

                for cell in dest_check(last_cell):
                    if cell == dest:
                        return path + [cell]

                checked_cells.add(last_cell)

                cells = self.get_adjacent_visible_cells(last_cell)
                cells = cells - path_cells
                for cell in cells:
                    new_path = path + [cell]
                    new_paths.append(new_path)
                    path_cells.add(cell)

            paths = new_paths
示例#18
0
 def __init__(self, id, binDir, binName = 'hylores'):
     Prover.__init__(self,id)
     self.binLocation = '%s/%s' % (binDir, binName)
     self.complStr    = 'sDMBLV'
     self.selFuncStr  = 'dboan'
     self.statsStr    = 'rgG:'
示例#19
0
 def __init__(self, id, binDir, binName = 'htab', extraArgs=''):
   Prover.__init__(self, id)
   self.binLocation = '%s/%s' % (binDir, binName)
   self.statsStr    = ':0:c'
   self.extraArgs   = extraArgs.split()
示例#20
0
 def __init__(self, id, binDir, binName = 'bliksem'):
     Prover.__init__(self, id)
     self.__binLocation = '%s/%s' % (binDir, binName)
     self.__timedRun    = '%s/timed-run' % binDir
示例#21
0
 def __init__(self, translatorId, binDir, binName, prover):
     Prover.__init__(self, '%s+%s' % (prover.id, translatorId))
     self.translatorId = translatorId
     self.prover =  prover
     self.binDir =  binDir
     self.binName = binName
示例#22
0
 def __init__(self, id, binDir, format, binName = 'eprover'):
     Prover.__init__(self,id)
     self.__binLocation = '%s/%s' % (binDir, binName)
     self.__format      = format # tptp2 or tptp3
示例#23
0
 def __init__(self, id, binDir, binName = 'pellet.sh', version = v1_3):
     Prover.__init__(self,id)
     self.__binLocation = '%s/%s' % (binDir, binName)
     #self.__sortsParam  = sorts       #default is 1, but layered translation seems to work better with 0
     self.__version     = version
示例#24
0
 def __init__(self, id, binDir, binName = 'SPASS', translation = None, 
              options = ''):
     Prover.__init__(self,id)
     self.__binLocation = "%s/%s" % (binDir, binName)
     self.translation = translation
     self.options = options
示例#25
0
 def __init__(self, id, sorts, binDir, binName = 'spass'):
     Prover.__init__(self,id)
     self.__binLocation = '%s/%s' % (binDir, binName)
     self.__sortsParam  = sorts  # default is 1, but layered translation seems to work better with 0
示例#26
0
'''
 MVP - Zero-Knowledge API
'''

from prover import Prover
from verifier import Verifier
from console import Console
from subprocess import Popen, PIPE, STDOUT

if __name__ == '__main__':

    verifier = Popen(["python", "verifier.py"], stdin=PIPE, stdout=PIPE)
    Console.write(Verifier.getName(), verifier.communicate())
    prover = Popen(["python", "prover.py"], stdin=PIPE, stdout=PIPE)
    Console.write(Prover.getName(), prover.communicate())