Skip to content

Commit c2a6d24

Browse files
authored
Merge pull request #1 from AAU-Dat/Maltesius-patch-1
Update AarhusShuffle.py
2 parents c6cc932 + 2d1c681 commit c2a6d24

File tree

1 file changed

+28
-11
lines changed

1 file changed

+28
-11
lines changed

AarhusShuffle.py

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import random
22
import numpy as np
33

4+
45
def honest_shuffle(ciphertexts, water, indices, active_set):
56
"""Fair shuffle and average water among active cups only."""
67
active_indices = [i for i in indices if i in active_set]
@@ -10,20 +11,22 @@ def honest_shuffle(ciphertexts, water, indices, active_set):
1011
for i in active_indices:
1112
water[i] = average
1213

13-
#waterclone = water.copy()
14+
# waterclone = water.copy()
1415

1516
# Shuffle ciphertexts
1617
sublist = [ciphertexts[i] for i in indices]
1718
random.shuffle(sublist)
1819
for idx, val in zip(indices, sublist):
1920
ciphertexts[idx] = val
20-
#water[idx] = waterclone[val]
21+
# water[idx] = waterclone[val]
22+
2123

2224
def adversarial_shuffle(ciphertexts, water, indices):
2325
"""Adversarial shuffler does nothing."""
2426
pass
2527

26-
def distributed_shuffle_with_water(n, k, T, beta, alpha):
28+
29+
def distributed_shuffle_with_water(n, k, T, alpha):
2730
ciphertexts = list(range(0, n))
2831
water = [0.0] * n
2932
water[0] = 1.0 # Initial water in cup 0
@@ -32,7 +35,7 @@ def distributed_shuffle_with_water(n, k, T, beta, alpha):
3235
threshold = 2 / (n - alpha)
3336

3437
res = []
35-
while True: #for t in range(T):
38+
while True:
3639

3740
indices = random.sample(range(n), k)
3841
honest_shuffle(ciphertexts, water, indices, active_set)
@@ -45,25 +48,39 @@ def distributed_shuffle_with_water(n, k, T, beta, alpha):
4548

4649
return res
4750

51+
# Return True if successful
4852

49-
# Return True if successful
5053

5154
# Run 100 trials
52-
def run_experiments(num_trials=100, n=16384, k=128, T=8192, beta=7112, alpha=8192):
55+
def run_experiments(num_trials=1000, n=16384, k=128, T=8192, alpha=8192):
5356
successes = 0
5457
result = [[] for i in range(num_trials)]
5558
for i in range(num_trials):
56-
res = distributed_shuffle_with_water(n, k, T, beta, alpha)
57-
for j,elem in enumerate(res):
59+
res = distributed_shuffle_with_water(n, k, T, alpha)
60+
for j, elem in enumerate(res):
5861
result[i].append(elem)
5962

6063
first_success_indices = [lst.index("success") for lst in result]
6164

62-
pcts = [20,40,60,80,100]
65+
pcts = [20, 40, 60, 80, 100]
6366

6467
ps = np.percentile(first_success_indices, pcts, method='nearest').astype(int)
6568

69+
res = ""
6670
for p, idx in zip(pcts, ps):
67-
print(f"{p}% of runs have succeeded by step {idx}")
71+
res += str(idx) + ","
72+
with open("results.txt", "a") as f:
73+
f.write(f"{k},{alpha}," + res + "\n")
74+
75+
76+
def benchmark_run():
77+
with open("results.txt", "a") as f:
78+
f.write("k,alpha,20pt,40pt,60pt,80pt,100pt,\n")
79+
for k in range(64, 129):
80+
for alpha in [4096, 5462, 8192]:
81+
run_experiments(k=k, alpha=alpha)
82+
83+
6884
if __name__ == "__main__":
69-
run_experiments()
85+
# run_experiments()
86+
benchmark_run()

0 commit comments

Comments
 (0)