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 wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/apps/multiply.py	Thu Nov 13 12:42:16 2008 +0100
@@ -0,0 +1,50 @@
+#!/usr/bin/python
+
+# Copyright 2008 VIFF Development Team.
+#
+# This file is part of VIFF, the Virtual Ideal Functionality Framework.
+#
+# VIFF is free software: you can redistribute it and/or modify it
+# under the terms of the GNU Lesser General Public License (LGPL) as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# VIFF is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
+# Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with VIFF. If not, see <http://www.gnu.org/licenses/>.
+
+from optparse import OptionParser
+from twisted.internet import reactor
+
+from viff.field import GF
+from viff.runtime import create_runtime, BasicRuntime
+from viff.config import load_config
+
+parser = OptionParser()
+BasicRuntime.add_options(parser)
+(options, args) = parser.parse_args()
+
+Zp = GF(1031)
+
+id, players = load_config(args[0])
+input = int(args[1])
+
+def protocol(rt):
+
+    def got_result(result):
+        print "Product:", result
+        rt.shutdown()
+
+    x, y, z = rt.shamir_share([1, 2, 3], Zp, input)
+    product = x * y * z
+    opened_product = rt.open(product)
+    opened_product.addCallback(got_result)
+
+pre_runtime = create_runtime(id, players, 1)
+pre_runtime.addCallback(protocol)
+
+reactor.run()