Пример #1
0
def differential(P, Q):
    """Polynomial differential operator

Parameters
----------
P : Poly
    Polynomial to be differentiated.
Q : Poly
    Polynomial to differentiate by. Must be decomposed. If
    polynomial array, the output is the Jacobian matrix.
    """
    P, Q = Poly(P), Poly(Q)

    if not is_decomposed(Q):
        differential(decompose(Q)).sum(0)

    if Q.shape:
        return Poly([differential(P, q) for q in Q])

    if Q.dim > P.dim:
        P = setdim(P, Q.dim)
    else:
        Q = setdim(Q, P.dim)

    qkey = Q.keys[0]

    A = {}
    for key in P.keys:

        newkey = np.array(key) - np.array(qkey)

        if np.any(newkey < 0):
            continue

        A[tuple(newkey)] = P.A[key]*np.prod([fac(key[i], \
            exact=True)/fac(newkey[i], exact=True) \
            for i in xrange(P.dim)])

    return Poly(A, P.dim, None)
Пример #2
0
def differential(P, Q):
    """Polynomial differential operator

Parameters
----------
P : Poly
    Polynomial to be differentiated.
Q : Poly
    Polynomial to differentiate by. Must be decomposed. If
    polynomial array, the output is the Jacobian matrix.
    """
    P, Q = Poly(P), Poly(Q)

    if not is_decomposed(Q):
        differential(decompose(Q)).sum(0)

    if Q.shape:
        return Poly([differential(P, q) for q in Q])

    if Q.dim > P.dim:
        P = setdim(P, Q.dim)
    else:
        Q = setdim(Q, P.dim)

    qkey = Q.keys[0]

    A = {}
    for key in P.keys:

        newkey = np.array(key) - np.array(qkey)

        if np.any(newkey < 0):
            continue

        A[tuple(newkey)] = P.A[key] * np.prod(
            [fac(key[i], exact=True) / fac(newkey[i], exact=True) for i in xrange(P.dim)]
        )

    return Poly(A, P.dim, None)
Пример #3
0
    server = WLSK_S.init()

    with socket.socket() as sock:
        sock.bind((my_addr, SERVER_PORT))
        sock.listen(1)

        print('Listening on \x1b[1m{}\x1b[0m:{} as a {}'.format(my_addr, SERVER_PORT, SERVER))

        while True:
            print('\nAwaiting connection...')
            conn, addr = sock.accept()
            print('Received connection from {0[0]}:{0[1]}'.format(addr))

            data = conn.recv(BUFFER_SIZE)
            (idA_, idB_, iv2, e_, m_) = base.decompose(data)
            delay()
            print('Received secrets from {}'.format(RESPONDER))
            debug("idA' = {}\nidB' = {}\ne'   = {}\nm'   = {}".format(idA_, idB_, iv2, e_, m_))

            (_, iv3, e__, m__) = server(idA_, idB_, iv2, e_, m_)
            delay()
            print('Sending secrets...')
            debug("e'' = {}\nm'' = {}".format(e__, m__))
            conn.send(base.compose([iv3, e__, m__]))
            conn.close()

            delay()
            print('\x1b[32mSession finished\x1b[0m')

Пример #4
0
            print('Received connection from {0[0]}:{0[1]}'.format(addr))

            idA = conn.recv(BUFFER_SIZE)
            print("{}'s identity is {}".format(INITIATOR, idA))
            delay()

            print('Generating nonce...')
            delay()
            (b4, n) = responder(idA)
            debug('n = {}'.format(n))
            conn.send(n)

            data = conn.recv(BUFFER_SIZE)
            conn.close()

            (iv1, e, m) = base.decompose(data)
            print('Received secrets from {}'.format(INITIATOR))
            debug('e = {}\nm = {}'.format(e, m))

            (b6, idA_, idB_, iv2, e_, m_) = b4(iv1, e, m)

            print('Connecting to the {}...'.format(SERVER))
            delay()
            with socket.create_connection((server_addr, SERVER_PORT)) as ssock:
                print('Sending encrypted data...')
                debug("idA' = {}\nidB' = {}\ne'   = {}\nm'   = {}".format(idA_, idB_, iv2, e_, m_))
                delay()
                ssock.send(base.compose([idA_, idB_, iv2, e_, m_]))

                data = ssock.recv(BUFFER_SIZE)