mirror of
https://github.com/data61/MP-SPDZ.git
synced 2026-04-20 03:01:31 -04:00
59 lines
865 B
Plaintext
59 lines
865 B
Plaintext
# (C) 2016 University of Bristol. See License.txt
|
|
|
|
def test(actual, expected):
|
|
if isinstance(actual, (sint, sgf2n)):
|
|
actual = actual.reveal()
|
|
print_ln('expected %s, got %s', expected, actual)
|
|
|
|
# cint: clear integers modulo p
|
|
# sint: secret integers modulo p
|
|
|
|
a = sint(1)
|
|
b = cint(2)
|
|
|
|
test(a + b, 3)
|
|
test(a + a, 2)
|
|
test(a * b, 2)
|
|
test(a * a, 1)
|
|
test(a - b, -1)
|
|
test(a < b, 1)
|
|
test(a <= b, 1)
|
|
test(a >= b, 0)
|
|
test(a > b, 0)
|
|
test(a == b, 0)
|
|
test(a != b, 1)
|
|
|
|
clear_a = a.reveal()
|
|
|
|
# sgfn2/cgf2n: secret/clear elements of GF(2^n)
|
|
|
|
a = sgf2n(1)
|
|
b = cgf2n(2)
|
|
|
|
test(a + b, 3)
|
|
test(a + a, 0)
|
|
test(a * b, 2)
|
|
test(a * a, 1)
|
|
test(a == b, 0)
|
|
test(a != b, 1)
|
|
|
|
# arrays and loops
|
|
|
|
a = Array(100, sint)
|
|
|
|
@for_range(100)
|
|
def f(i):
|
|
a[i] = sint(i)**2
|
|
|
|
test(a[99], 99**2)
|
|
|
|
# conditional
|
|
|
|
if_then(cint(0))
|
|
a[0] = 123
|
|
else_then()
|
|
a[0] = 789
|
|
end_if()
|
|
|
|
test(a[0], 789)
|