Exemplo n.º 1
0
    def _createInsertString(self, a, b, x, y, length):
        aHex = util.toHex(a)
        bHex = util.toHex(b)
        endHex = util.compress_point(x, y)

        return "INSERT INTO %s(StartA, StartB, EndPoint, WalkLength) VALUES('%s', '%s', '%s', %d);" % (
            self.name, aHex, bHex, endHex, length)
Exemplo n.º 2
0
    def insertRPoint(self, cursor, name, idx, a, b, x, y):
        xHex = util.toHex(x)
        yHex = util.toHex(y)
        aHex = util.toHex(a)
        bHex = util.toHex(b)

        s = "INSERT INTO RPoints(Name, Idx, A, B, X, Y) VALUES('%s', %d, '%s', '%s', '%s', '%s');" % (name, idx, aHex, bHex, xHex, yHex)

        cursor.execute(s)
Exemplo n.º 3
0
    def insertRPoint(self, cursor, name, idx, a, b, x, y):
        xHex = util.toHex(x)
        yHex = util.toHex(y)
        aHex = util.toHex(a)
        bHex = util.toHex(b)

        s = "INSERT INTO RPoints(Name, Idx, A, B, X, Y) VALUES('%s', %d, '%s', '%s', '%s', '%s');" % (
            name, idx, aHex, bHex, xHex, yHex)

        cursor.execute(s)
Exemplo n.º 4
0
    def _createMultipleInsertString(self, points):
        statement = "INSERT INTO %s(StartA, StartB, EndPoint, WalkLength) VALUES " % (self.name)

        for i in xrange(len(points)):
            aHex = util.toHex(points[i]['a'])
            bHex = util.toHex(points[i]['b'])
            endHex = util.compress_point(points[i]['x'], points[i]['y'])

            statement += "('%s', '%s', '%s', %d)" % (aHex, bHex, endHex, points[i]['length'])
            if i < len(points) - 1:
                statement += ","

        statement += ";"

        return statement;
Exemplo n.º 5
0
    def setSolution(self, value):
        cursor = self.db.cursor()
        solutionHex = util.toHex(value)

        s = "UPDATE JobInfo SET Solution = '%s', Status = 'solved' WHERE Name = '%s';" % (
            solutionHex, self.name)
        cursor.execute(s)
Exemplo n.º 6
0
    def _createMultipleInsertString(self, points):
        statement = "INSERT INTO %s(StartA, StartB, EndPoint, WalkLength) VALUES " % (
            self.name)

        for i in xrange(len(points)):
            aHex = util.toHex(points[i]['a'])
            bHex = util.toHex(points[i]['b'])
            endHex = util.compress_point(points[i]['x'], points[i]['y'])

            statement += "('%s', '%s', '%s', %d)" % (aHex, bHex, endHex,
                                                     points[i]['length'])
            if i < len(points) - 1:
                statement += ","

        statement += ";"

        return statement
Exemplo n.º 7
0
def getDataToSend(hData, _type, asciiTail=""):
    """从本地数据和发送类型获取需要发送的数据"""
    data = "SYS-ERROR"
    ret = True
    if _type == config.HEX_TYPE:
        data = util.toHex(''.join(hData.split()))
    elif _type == config.ASCII_TYPE:
        data = hData + asciiTail

    return ret, data
Exemplo n.º 8
0
    def insertParams(self, cursor, name, p, a, b, n, gx, gy, qx, qy, dBits):
        pHex = util.toHex(p)
        aHex = util.toHex(a)
        bHex = util.toHex(b)
        nHex = util.toHex(n)
        gxHex = util.toHex(gx)
        gyHex = util.toHex(gy)
        qxHex = util.toHex(qx)
        qyHex = util.toHex(qy)

        s = ("INSERT INTO JobParams(Name, P, A, B, N, Gx, Gy, Qx, Qy, DBits) "
            "VALUES('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d);") % (name, pHex, aHex, bHex, nHex, gxHex, gyHex, qxHex, qyHex, dBits)
        cursor.execute(s)
Exemplo n.º 9
0
 def charParser(socket):
     data = socket.recv(1024)
     print len(data)
     if len(data) < 4:
         log.error("Char login bad error")
         return
     if data.startswith(conn.accountID):
         data = data[4:]
         if len(data) == 0:
             return
     
     (header,) = struct.unpack('H', data[0:2])
     if header == 0x6c:
         log.error("Char login denied")
         return
     elif header == 0x81:
         log.error("Already logged in")
         return
     elif header == 0x71:
         mapname = data[6:22].split('\x00\x00')[0]
         conn.mapname = mapname
         socket.close()
         event.removeSocket(socket)
         event.addEvent(lambda: self.mapConnect(conn), 0)
     elif header == 0x6b:
         (length,) = struct.unpack('H', data[2:4])
         if (length - 24) % 108 == 0:
             charlen = 108
         elif (length - 24) % 106 == 0:
             charlen = 106
             
         numChars = (length - 24) / charlen
         
         log.info("Number of characters: %d",numChars)
         
         for i in range(0, numChars):
             offset = 24 + i * charlen
             res = struct.unpack('IIIIIIIIIIHHHHHHHHHHHHHHHHH24sBBBBBBH', data[offset:offset+106])
             if conn.slot == res[34]:
                 conn.charID = res[0]
                 log.info('CharId: %s', util.toHex(struct.pack('I', conn.charID)))
                 conn.baseExp = res[1]
                 conn.zeny = res[2]
                 conn.jobExp = res[3]
                 conn.jobLevel = res[4]
                 conn.hp = res[11]
                 conn.maxhp = res[12]
                 conn.sp = res[13]
                 conn.maxsp = res[14]
                 conn.charname = res[27].split('\x00')[0]
                 socket.send('\x87\x01' + conn.accountID);
                 socket.send(struct.pack('bxb', 0x66, conn.slot));
Exemplo n.º 10
0
    def insertParams(self, cursor, name, p, a, b, n, gx, gy, qx, qy, dBits):
        pHex = util.toHex(p)
        aHex = util.toHex(a)
        bHex = util.toHex(b)
        nHex = util.toHex(n)
        gxHex = util.toHex(gx)
        gyHex = util.toHex(gy)
        qxHex = util.toHex(qx)
        qyHex = util.toHex(qy)

        s = (
            "INSERT INTO JobParams(Name, P, A, B, N, Gx, Gy, Qx, Qy, DBits) "
            "VALUES('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d);"
        ) % (name, pHex, aHex, bHex, nHex, gxHex, gyHex, qxHex, qyHex, dBits)
        cursor.execute(s)
Exemplo n.º 11
0
def encryptStringToHex(P, KEY):
    assert (len(KEY) == 16), 'KEY is not the correct size: encryptString'
    extra = 8 - len(P) % 8
    if extra % 8 != 0:
        P = P + ' ' * (extra)
    l = []
    for i in range(0, len(P), 8):
        p = P[i: i + 8]

        P_x = toHex(p)
        C_x = encryptHex(P_x, KEY)
        # yield (C_x)
        l.append(C_x)
    return ''.join(l)
Exemplo n.º 12
0
    def insertCollision(self, a1, b1, length1, a2, b2, length2, x, y):

        cursor = self.db.cursor()

        a1Hex = util.toHex(a1)
        b1Hex = util.toHex(b1) 
        a2Hex = util.toHex(a2)
        b2Hex = util.toHex(b2)
        xHex = util.toHex(x)
        yHex = util.toHex(y)

        s = "INSERT INTO Collisions(Name, A1, B1, WalkLength1, A2, B2, WalkLength2, X, Y) VALUES('%s', '%s', '%s', %d, '%s', '%s', %d, '%s', '%s');" % (self.name, a1Hex, b1Hex,length1, a2Hex, b2Hex, length2, xHex, yHex)
        cursor.execute(s)
Exemplo n.º 13
0
    def insertCollision(self, a1, b1, length1, a2, b2, length2, x, y):

        cursor = self.db.cursor()

        a1Hex = util.toHex(a1)
        b1Hex = util.toHex(b1)
        a2Hex = util.toHex(a2)
        b2Hex = util.toHex(b2)
        xHex = util.toHex(x)
        yHex = util.toHex(y)

        s = "INSERT INTO Collisions(Name, A1, B1, WalkLength1, A2, B2, WalkLength2, X, Y) VALUES('%s', '%s', '%s', %d, '%s', '%s', %d, '%s', '%s');" % (
            self.name, a1Hex, b1Hex, length1, a2Hex, b2Hex, length2, xHex,
            yHex)
        cursor.execute(s)
Exemplo n.º 14
0
def solveNextCollision(ctx):

    ctx.database.open()
    coll = ctx.database.getNextCollision()
    ctx.database.close()

    if coll == None:
        return

    solver = RhoSolver(ctx.params, ctx.rPoints, coll['a1'], coll['b1'], coll['a2'], coll['b2'], ECPoint(coll['x'], coll['y']))

    solver.solve()

    ctx.database.open()

    if solver.solved == True:
        print("The solution is " + util.toHex(solver.k))
        ctx.database.setSolution(solver.k)
        ctx.database.updateCollisionStatus(coll['id'], 'T')
    else:
        ctx.database.updateCollisionStatus(coll['id'], 'F')

    ctx.database.close()
Exemplo n.º 15
0
def solveNextCollision(ctx):

    ctx.database.open()
    coll = ctx.database.getNextCollision()
    ctx.database.close()

    if coll == None:
        return

    solver = RhoSolver(ctx.params, ctx.rPoints, coll['a1'], coll['b1'],
                       coll['a2'], coll['b2'], ECPoint(coll['x'], coll['y']))

    solver.solve()

    ctx.database.open()

    if solver.solved == True:
        print("The solution is " + util.toHex(solver.k))
        ctx.database.setSolution(solver.k)
        ctx.database.updateCollisionStatus(coll['id'], 'T')
    else:
        ctx.database.updateCollisionStatus(coll['id'], 'F')

    ctx.database.close()
Exemplo n.º 16
0
 def _cmd_add_ssid(self, network_id, ssid):
     return cmd("sudo wpa_cli set_network {} ssid {}".format(network_id, toHex(ssid)))
Exemplo n.º 17
0
    def _createInsertString(self, a, b, x, y, length):
        aHex = util.toHex(a)
        bHex = util.toHex(b)
        endHex = util.compress_point(x, y)

        return "INSERT INTO %s(StartA, StartB, EndPoint, WalkLength) VALUES('%s', '%s', '%s', %d);" % (self.name, aHex, bHex, endHex, length)
Exemplo n.º 18
0
    def setSolution(self, value):
        cursor = self.db.cursor()
        solutionHex = util.toHex(value)

        s = "UPDATE JobInfo SET Solution = '%s', Status = 'solved' WHERE Name = '%s';" % (solutionHex, self.name)
        cursor.execute(s)