viff
view apps/divide.py @ 1575:cfb8e1485006
Updated email address.
| author | Thomas P Jakobsen <tpj@cs.au.dk> |
|---|---|
| date | Wed Dec 15 13:00:00 2010 +0100 (17 months ago) |
| parents | 6cd5ceb87542 |
| children |
line source
1 #!/usr/bin/env python
3 # Copyright 2008 VIFF Development Team.
4 #
5 # This file is part of VIFF, the Virtual Ideal Functionality Framework.
6 #
7 # VIFF is free software: you can redistribute it and/or modify it
8 # under the terms of the GNU Lesser General Public License (LGPL) as
9 # published by the Free Software Foundation, either version 3 of the
10 # License, or (at your option) any later version.
11 #
12 # VIFF is distributed in the hope that it will be useful, but WITHOUT
13 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
15 # Public License for more details.
16 #
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with VIFF. If not, see <http://www.gnu.org/licenses/>.
19 #
21 """This program does a secret division between two secret shared
22 values. It is of course mostly meaningless for this example (you can
23 compute the inputs from your own value and the output).
25 The program can be run as follows for each player (min 3) where 24 is
26 the number we would like to divide (by):
28 $ python division.py player-X.ini 24
30 Only the numbers of player 1 and player 2 are actually used, but
31 more players are necessary for the security.
32 """
51 """Returns a share of of ``x/y`` (rounded down).
53 Precondition: ``2**l * y < x.field.modulus``.
55 If ``y == 0`` return ``(2**(l+1) - 1)``.
57 The division is done by making a comparison for every
58 i with ``(2**i)*y`` and *x*.
59 Protocol by Sigurd Meldgaard.
61 Communication cost: *l* rounds of comparison.
63 Also works for simple integers:
64 >>>divide(3, 3, 2)
65 1
66 >>>divide(50, 10, 10)
67 5
68 """
79 # Parse command line arguments.
100 # Load configuration file.
109 # Players 1 and 2 are doing a sharing over the field Zp.
110 # Our input is number (None for other players).
117 # Do the secret computation.
120 # Now open the result so we can see it.
127 # Start the Twisted event loop.
