Skip to content

Commit 5b5d842

Browse files
committed
Create shamir secret sharing voting notebook
1 parent 394dc5f commit 5b5d842

File tree

2 files changed

+569
-20
lines changed

2 files changed

+569
-20
lines changed

projects/pryvote/demo/secure_multi_party_voting.ipynb renamed to projects/pryvote/demo/1_secure_multi_party_voting.ipynb

Lines changed: 89 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
},
3737
{
3838
"cell_type": "code",
39-
"execution_count": null,
39+
"execution_count": 1,
4040
"metadata": {},
4141
"outputs": [],
4242
"source": [
@@ -57,7 +57,7 @@
5757
},
5858
{
5959
"cell_type": "code",
60-
"execution_count": null,
60+
"execution_count": 2,
6161
"metadata": {},
6262
"outputs": [],
6363
"source": [
@@ -82,7 +82,7 @@
8282
},
8383
{
8484
"cell_type": "code",
85-
"execution_count": null,
85+
"execution_count": 3,
8686
"metadata": {},
8787
"outputs": [],
8888
"source": [
@@ -109,7 +109,7 @@
109109
},
110110
{
111111
"cell_type": "code",
112-
"execution_count": null,
112+
"execution_count": 4,
113113
"metadata": {},
114114
"outputs": [],
115115
"source": [
@@ -124,7 +124,7 @@
124124
" vote_class = pricon_vote.get_vote_class(vote_value)\n",
125125
"\n",
126126
" onehot_votes = [0] * len(pricon_vote)\n",
127-
" onehot_votes[vote_class] = 1\n",
127+
" onehot_votes[vote_class] = 1 # [1, 0, 0]\n",
128128
" \n",
129129
" vote_shares = [self._encrypt_vote(binary_vote) for binary_vote in onehot_votes]\n",
130130
"\n",
@@ -134,9 +134,9 @@
134134
" self._vote_shares = None\n",
135135
"\n",
136136
" def _encrypt_vote(self, vote: int):\n",
137-
" share_a = random.randint(-Q,Q)\n",
138-
" share_b = random.randint(-Q,Q)\n",
139-
" share_c = (vote - share_a - share_b) % Q\n",
137+
" share_a = random.randint(-self._Q,self._Q)\n",
138+
" share_b = random.randint(-self._Q,self._Q)\n",
139+
" share_c = (vote - share_a - share_b) % self._Q\n",
140140
" return (share_a, share_b, share_c)\n",
141141
"\n",
142142
" def send_vote(self, parties) -> None:\n",
@@ -152,7 +152,7 @@
152152
},
153153
{
154154
"cell_type": "code",
155-
"execution_count": null,
155+
"execution_count": 5,
156156
"metadata": {},
157157
"outputs": [],
158158
"source": [
@@ -183,7 +183,7 @@
183183
},
184184
{
185185
"cell_type": "code",
186-
"execution_count": null,
186+
"execution_count": 6,
187187
"metadata": {},
188188
"outputs": [],
189189
"source": [
@@ -201,7 +201,7 @@
201201
},
202202
{
203203
"cell_type": "code",
204-
"execution_count": null,
204+
"execution_count": 7,
205205
"metadata": {},
206206
"outputs": [],
207207
"source": [
@@ -212,7 +212,7 @@
212212
},
213213
{
214214
"cell_type": "code",
215-
"execution_count": null,
215+
"execution_count": 8,
216216
"metadata": {},
217217
"outputs": [],
218218
"source": [
@@ -244,7 +244,7 @@
244244
},
245245
{
246246
"cell_type": "code",
247-
"execution_count": null,
247+
"execution_count": 9,
248248
"metadata": {},
249249
"outputs": [],
250250
"source": [
@@ -259,9 +259,37 @@
259259
},
260260
{
261261
"cell_type": "code",
262-
"execution_count": null,
262+
"execution_count": 10,
263263
"metadata": {},
264-
"outputs": [],
264+
"outputs": [
265+
{
266+
"name": "stdout",
267+
"output_type": "stream",
268+
"text": [
269+
"red: Adding vote for 3a29334a-cff6-4a73-b681-29aa0bd3be41\n",
270+
"blue: Adding vote for 3a29334a-cff6-4a73-b681-29aa0bd3be41\n",
271+
"yellow: Adding vote for 3a29334a-cff6-4a73-b681-29aa0bd3be41\n",
272+
"red: Adding vote for c33db94b-8e5b-488f-ac39-91c74491f123\n",
273+
"blue: Adding vote for c33db94b-8e5b-488f-ac39-91c74491f123\n",
274+
"yellow: Adding vote for c33db94b-8e5b-488f-ac39-91c74491f123\n",
275+
"red: Adding vote for 0347145d-dd85-4ef8-930f-12dcff90190e\n",
276+
"blue: Adding vote for 0347145d-dd85-4ef8-930f-12dcff90190e\n",
277+
"yellow: Adding vote for 0347145d-dd85-4ef8-930f-12dcff90190e\n",
278+
"red: Adding vote for 5d88aa47-a73a-4e04-9111-fa0f0fef189d\n",
279+
"blue: Adding vote for 5d88aa47-a73a-4e04-9111-fa0f0fef189d\n",
280+
"yellow: Adding vote for 5d88aa47-a73a-4e04-9111-fa0f0fef189d\n",
281+
"red: Adding vote for 7e41730d-4270-490f-b227-a3ee719373eb\n",
282+
"blue: Adding vote for 7e41730d-4270-490f-b227-a3ee719373eb\n",
283+
"yellow: Adding vote for 7e41730d-4270-490f-b227-a3ee719373eb\n",
284+
"red: Adding vote for eb09cd17-166f-4fa4-8a89-ac7a199119e3\n",
285+
"blue: Adding vote for eb09cd17-166f-4fa4-8a89-ac7a199119e3\n",
286+
"yellow: Adding vote for eb09cd17-166f-4fa4-8a89-ac7a199119e3\n",
287+
"red: Adding vote for fd992cfa-bb52-4fdd-b42f-90c2b1107ac4\n",
288+
"blue: Adding vote for fd992cfa-bb52-4fdd-b42f-90c2b1107ac4\n",
289+
"yellow: Adding vote for fd992cfa-bb52-4fdd-b42f-90c2b1107ac4\n"
290+
]
291+
}
292+
],
265293
"source": [
266294
"for voter in [alice, bob, charlie, dan, eve, fran, greg]:\n",
267295
" voter.send_vote([red, blue, yellow])"
@@ -276,9 +304,20 @@
276304
},
277305
{
278306
"cell_type": "code",
279-
"execution_count": null,
307+
"execution_count": 11,
280308
"metadata": {},
281-
"outputs": [],
309+
"outputs": [
310+
{
311+
"data": {
312+
"text/plain": [
313+
"[-1689120296584, -1384865635954, -859978157999]"
314+
]
315+
},
316+
"execution_count": 11,
317+
"metadata": {},
318+
"output_type": "execute_result"
319+
}
320+
],
282321
"source": [
283322
"red._vote_sum"
284323
]
@@ -303,9 +342,18 @@
303342
},
304343
{
305344
"cell_type": "code",
306-
"execution_count": null,
345+
"execution_count": 12,
307346
"metadata": {},
308-
"outputs": [],
347+
"outputs": [
348+
{
349+
"name": "stdout",
350+
"output_type": "stream",
351+
"text": [
352+
"Vote counts are [3, 2, 2]\n",
353+
"PryVote is the winner!\n"
354+
]
355+
}
356+
],
309357
"source": [
310358
"total_sums = []\n",
311359
"\n",
@@ -360,6 +408,27 @@
360408
"This could be solved by policy,\n",
361409
"such as frequent, independent auditing of a running vote aggregation during the lifetime of a vote session."
362410
]
411+
},
412+
{
413+
"cell_type": "code",
414+
"execution_count": null,
415+
"metadata": {},
416+
"outputs": [],
417+
"source": []
418+
},
419+
{
420+
"cell_type": "code",
421+
"execution_count": null,
422+
"metadata": {},
423+
"outputs": [],
424+
"source": []
425+
},
426+
{
427+
"cell_type": "code",
428+
"execution_count": null,
429+
"metadata": {},
430+
"outputs": [],
431+
"source": []
363432
}
364433
],
365434
"metadata": {
@@ -378,7 +447,7 @@
378447
"name": "python",
379448
"nbconvert_exporter": "python",
380449
"pygments_lexer": "ipython3",
381-
"version": "3.8.5"
450+
"version": "3.7.9"
382451
}
383452
},
384453
"nbformat": 4,

0 commit comments

Comments
 (0)