viff

changeset 1029:e31181b3c703

Added simple multiplication example.
author Martin Geisler <mg@daimi.au.dk>
date Thu, 13 Nov 2008 12:42:16 +0100
parents 54c25924882a
children b4f94a0d9a76
files apps/multiply.py
diffstat 1 files changed, 50 insertions(+), 0 deletions(-) [+]
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/apps/multiply.py	Thu Nov 13 12:42:16 2008 +0100
     1.3 @@ -0,0 +1,50 @@
     1.4 +#!/usr/bin/python
     1.5 +
     1.6 +# Copyright 2008 VIFF Development Team.
     1.7 +#
     1.8 +# This file is part of VIFF, the Virtual Ideal Functionality Framework.
     1.9 +#
    1.10 +# VIFF is free software: you can redistribute it and/or modify it
    1.11 +# under the terms of the GNU Lesser General Public License (LGPL) as
    1.12 +# published by the Free Software Foundation, either version 3 of the
    1.13 +# License, or (at your option) any later version.
    1.14 +#
    1.15 +# VIFF is distributed in the hope that it will be useful, but WITHOUT
    1.16 +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
    1.17 +# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
    1.18 +# Public License for more details.
    1.19 +#
    1.20 +# You should have received a copy of the GNU Lesser General Public
    1.21 +# License along with VIFF. If not, see <http://www.gnu.org/licenses/>.
    1.22 +
    1.23 +from optparse import OptionParser
    1.24 +from twisted.internet import reactor
    1.25 +
    1.26 +from viff.field import GF
    1.27 +from viff.runtime import create_runtime, BasicRuntime
    1.28 +from viff.config import load_config
    1.29 +
    1.30 +parser = OptionParser()
    1.31 +BasicRuntime.add_options(parser)
    1.32 +(options, args) = parser.parse_args()
    1.33 +
    1.34 +Zp = GF(1031)
    1.35 +
    1.36 +id, players = load_config(args[0])
    1.37 +input = int(args[1])
    1.38 +
    1.39 +def protocol(rt):
    1.40 +
    1.41 +    def got_result(result):
    1.42 +        print "Product:", result
    1.43 +        rt.shutdown()
    1.44 +
    1.45 +    x, y, z = rt.shamir_share([1, 2, 3], Zp, input)
    1.46 +    product = x * y * z
    1.47 +    opened_product = rt.open(product)
    1.48 +    opened_product.addCallback(got_result)
    1.49 +
    1.50 +pre_runtime = create_runtime(id, players, 1)
    1.51 +pre_runtime.addCallback(protocol)
    1.52 +
    1.53 +reactor.run()