Exemple #1
0
    def test_share(self):
        x = torch.LongTensor([-3])

        spdz_x = x.share(alice, bob, james)
        assert len(spdz_x.child.shares.child.pointer_tensor_dict.keys()) == 3

        spdz_x.get()

        assert sy.eq(spdz_x, sy.LongTensor([-3])).all()
Exemple #2
0
def swap_shares(shares):
    ptd = shares.child.pointer_tensor_dict
    alice, bob = list(ptd.keys())
    new_alice = (ptd[alice]+0)
    new_bob = (ptd[bob]+0)
    new_alice.send(bob)
    new_bob.send(alice)

    return sy._GeneralizedPointerTensor({alice: new_bob,bob: new_alice}).on(sy.LongTensor([]))
Exemple #3
0
def string2values(str_input, max_len=128):
    # truncate strings longer than max_len
    str_input = str_input[:max_len].lower()

    # pad strings shorter than max_len
    if (len(str_input) < max_len):
        str_input = str_input + "." * (max_len - len(str_input))

    values = list()
    for char in str_input:
        values.append(char2int[char])

    return sy.LongTensor(values)
Exemple #4
0
def string2values(key, input_str):
    values = list()
    for char in input_str:
        values.append(char2int[char])
    return sy.LongTensor(values)
Exemple #5
0
def string2key(input_str):
    return sy.LongTensor([hash(input_str) % sy.mpc.securenn.field])