Mercurial > pysmcl
changeset 221:1727a6ce0442
functions: added a couple more dummy functions
author | Sigurd Meldgaard <stm@daimi.au.dk> |
---|---|
date | Wed, 23 Dec 2009 14:35:43 +0100 |
parents | 01a6d95bf029 |
children | 83996d1a8c4d |
files | pysmcl/functions.py |
diffstat | 1 files changed, 26 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/pysmcl/functions.py Wed Dec 23 14:34:38 2009 +0100 +++ b/pysmcl/functions.py Wed Dec 23 14:35:43 2009 +0100 @@ -1,13 +1,33 @@ from twisted.internet.defer import inlineCallbacks import pysmcl.setup +import random #from viff. import -def get(runtime, prompt): - """ Queries each player for an integer, and returns a list of sharings - of the respective values. """ - print(prompt) - a = raw_input() - return runtime.shamir_share(runtime.players, pysmcl.setup.Zp, int(a)) +def get(runtime, prompt, player, lower, upper): + """ Queries player for an integer in the interval between lower + and upper, and returns a sharing of the value.""" + if runtime.id == player: + print(prompt) + print("Please enter a number in the interval from %d to %d" % + (lower, upper)) + # a = int(raw_input()) + a = random.randint(lower, upper);print "chose %d for you!" % a + if(a < lower or a >= upper): + raise RuntimeError("Invalid value shared") + return runtime.shamir_share([player], pysmcl.setup.Zp, a) + else: + return runtime.shamir_share([player], pysmcl.setup.Zp) def precondition(args): pass + +def num_players(runtime): + return runtime.num_players + +def player(runtime): + return runtime.id + +def random(runtime): + # TODO: what is the right thing here? + return runtime.prss_share_random() +