Пример #1
0
 def finish(result):
     self.progressbar.finish()
     print  # This line goes on top of the progressbar
     dprint("Original array: %s", array)
     dprint("Sorted array:   %s", result)
     print "Made %d comparisons" % self.comparisons
     runtime.shutdown()
Пример #2
0
def protocol(rt):
    l = 7

    rand = dict([(i, random.Random(i)) for i in players])

    inputs = []
    for i in range(count):
        input = dict([(j, rand[j].randint(0, pow(2, l))) for j in players])
        inputs.append(input)

    # Fixed input for easier debugging
    inputs.append({1: 20, 2: 25, 3: 0})

    print "I am player %d, will compare %d numbers" % (id, len(inputs))

    bits = []
    for input in inputs:
        x, y, z = rt.shamir_share([1, 2, 3], Zp, input[id])
        bit = rt.open(x >= y)
        bit.addCallback(lambda b: b == GF256(1))
        bit.addCallback(lambda b, x, y: "%3d >= %3d: %-5s (%s)" \
                            % (x, y, b, b == (x >= y)), input[1], input[2])
        dprint("%s", bit)
        bits.append(bit)

    results = gatherResults(bits)
    results.addCallback(lambda _: rt.shutdown())
Пример #3
0
def protocol(rt):
    l = 7

    rand = dict([(i, random.Random(i)) for i in players])

    inputs = []
    for i in range(count):
        input = dict([(j, rand[j].randint(0, pow(2, l))) for j in players])
        inputs.append(input)

    # Fixed input for easier debugging
    inputs.append({1: 20, 2: 25, 3: 0})

    print "I am player %d, will compare %d numbers" % (id, len(inputs))

    bits = []
    for input in inputs:
        x, y, z = rt.shamir_share([1, 2, 3], Zp, input[id])
        bit = rt.open(x >= y)
        bit.addCallback(lambda b: b == GF256(1))
        bit.addCallback(lambda b, x, y: "%3d >= %3d: %-5s (%s)" \
                            % (x, y, b, b == (x >= y)), input[1], input[2])
        dprint("%s", bit)
        bits.append(bit)

    results = gatherResults(bits)
    results.addCallback(lambda _: rt.shutdown())
Пример #4
0
 def finish(result):
     self.progressbar.finish()
     print  # This line goes on top of the progressbar
     dprint("Original array: %s", array)
     dprint("Sorted array:   %s", result)
     print "Made %d comparisons" % self.comparisons
     runtime.shutdown()
Пример #5
0
def protocol(rt):
    print "-" * 64
    print "Program started"
    print

    shares = rt.prss_share([1, 2, 3], GF256, input)

    while len(shares) > 1:
        a = shares.pop(0)
        b = shares.pop(0)
        shares.append(a ^ b)

    xor = rt.open(shares[0])
    dprint("Result: %s", xor)
    rt.wait_for(xor)
Пример #6
0
def protocol(rt):
    print "-" * 64
    print "Program started"
    print

    shares = rt.prss_share([1, 2, 3], GF256, input)

    while len(shares) > 1:
        a = shares.pop(0)
        b = shares.pop(0)
        shares.append(a ^ b)

    xor = rt.open(shares[0])
    dprint("Result: %s", xor)
    rt.wait_for(xor)
Пример #7
0
    def run(runtime):
        print "Connected."

        # Players 1 and 2 are doing a sharing over the field Zp.
        # Our input is number (None for other players).
        if runtime.id == 3:
            print "I have no number"
        else:
            print "My number: %d." % number
        (x, y) = runtime.shamir_share([1, 2], Zp, number)

        # Do the secret computation.
        result = divide(x, y, 10) # 10 bits for the result.

        # Now open the result so we can see it.
        dprint("The two numbers divided are: %s", runtime.open(result))

        result.addCallback(lambda _: runtime.shutdown())
Пример #8
0
def protocol(runtime):
    print "-" * 64
    print "Program started"
    print

    # Each of the players [1, 2, 3] shares his input -- resulting in
    # three shares. The a share is the input from P1, b is from P2,
    # and c is from P3.
    a, b, c = runtime.input([1, 2, 3], Zp, input)

    # It is possible to make the players do different things by
    # branching on the players ID. In this case only P1 inputs a
    # number. The other two players must still participate in order to
    # get the hold of their share.
    if runtime.id == 1:
        s1 = runtime.input([1], Zp, 42)
    else:
        s1 = runtime.input([1], Zp, None)

    # Secure arithmetic works like normal.
    a = b + c
    b = c * s1

    # Outputting shares convert them from secret shared form into
    # cleartext. By default every player receives the cleartext.
    a = runtime.output(a)
    b = runtime.output(b)
    c = runtime.output(c)
    # Output s1 to player 2. The other players will receive None.
    s1 = runtime.output(s1, [2])

    dprint("### Output a to all: %s ###", a)
    dprint("### Output b to all: %s ###", b)
    dprint("### Output c to all: %s ###", c)

    # We only print the value of s1 for player 2, 
    # since only player 2 has the value of s1.
    if runtime.id == 2:
        dprint("### opened s1: %s ###", s1)
    
    # We wait for the evaluation of deferred a, b, c.
    runtime.wait_for(a, b, c)
Пример #9
0
def protocol(runtime):
    print "-" * 64
    print "Program started"
    print

    # Each of the players [1, 2, 3] shares his input -- resulting in
    # three shares. The a share is the input from P1, b is from P2,
    # and c is from P3.
    a, b, c = runtime.input([1, 2, 3], Zp, input)

    # It is possible to make the players do different things by
    # branching on the players ID. In this case only P1 inputs a
    # number. The other two players must still participate in order to
    # get the hold of their share.
    if runtime.id == 1:
        s1 = runtime.input([1], Zp, 42)
    else:
        s1 = runtime.input([1], Zp, None)

    # Secure arithmetic works like normal.
    a = b + c
    b = c * s1

    # Outputting shares convert them from secret shared form into
    # cleartext. By default every player receives the cleartext.
    a = runtime.output(a)
    b = runtime.output(b)
    c = runtime.output(c)
    # Output s1 to player 2. The other players will receive None.
    s1 = runtime.output(s1, [2])

    dprint("### Output a to all: %s ###", a)
    dprint("### Output b to all: %s ###", b)
    dprint("### Output c to all: %s ###", c)

    # We only print the value of s1 for player 2,
    # since only player 2 has the value of s1.
    if runtime.id == 2:
        dprint("### opened s1: %s ###", s1)

    # We wait for the evaluation of deferred a, b, c.
    runtime.wait_for(a, b, c)
Пример #10
0
def protocol(runtime):
    print "-" * 64
    print "Program started"
    print

    a, b, c = runtime.prss_share([1, 2, 3], GF256, input)

    a = runtime.open(a)
    b = runtime.open(b)
    c = runtime.open(c)

    dprint("### opened a: %s ###", a)
    dprint("### opened b: %s ###", b)
    dprint("### opened c: %s ###", c)

    runtime.wait_for(a, b, c)
Пример #11
0
def protocol(runtime):
    print "-" * 64
    print "Program started"
    print

    a, b, c = runtime.prss_share([1, 2, 3], GF256, input)

    a = runtime.open(a)
    b = runtime.open(b)
    c = runtime.open(c)

    dprint("### opened a: %s ###", a)
    dprint("### opened b: %s ###", b)
    dprint("### opened c: %s ###", c)

    runtime.wait_for(a, b, c)
Пример #12
0
def protocol(rt):
    print "-" * 64
    print "Program started"
    print

    a, b, c = rt.shamir_share([1, 2, 3], Zp, input)

    a = rt.open(a)
    b = rt.open(b)
    c = rt.open(c)

    dprint("### opened a: %s ###", a)
    dprint("### opened b: %s ###", b)
    dprint("### opened c: %s ###", c)

    rt.wait_for(a, b, c)
Пример #13
0
def protocol(rt):
    print "-" * 64
    print "Program started"
    print

    a, b, c = rt.shamir_share([1, 2, 3], Zp, input)

    a = rt.open(a)
    b = rt.open(b)
    c = rt.open(c)

    dprint("### opened a: %s ###", a)
    dprint("### opened b: %s ###", b)
    dprint("### opened c: %s ###", c)

    rt.wait_for(a, b, c)
Пример #14
0
def protocol(runtime):
    print "-" * 64
    print "Program started"
    print

    a, b = runtime.share([1, 2], Zp, input)
    c = a * b

    dprint("a%d: %s", runtime.id, a)
    dprint("b%d: %s", runtime.id, b)
    dprint("c%d: %s", runtime.id, c)

    a = runtime.open(a)
    b = runtime.open(b)
    c = runtime.open(c)

    dprint("### opened a: %s ###", a)
    dprint("### opened b: %s ###", b)
    dprint("### opened c: %s ###", c)

    runtime.wait_for(a, b, c)
Пример #15
0
def protocol(rt):
    elements = [rt.open(rt.prss_share_random(Z31)) for _ in range(10)]
    result = gatherResults(elements)
    dprint("bits: %s", result)

    rt.wait_for(result)