import random # Number of participants N = 20 Ns = range(N) # Number of Alice's friends |RA| = m m = 3 ms = random.sample(Ns, m) ms.sort() # To ease comparison # Size of Mix K K = 5 # Rounds to simulate t = 45 print "Parameters: N=%s m=%s K=%s t=%s" % (N, m, K, t) print "KA={%s}" % ms # Simulate Outputs = [] for Tt in xrange(t): o = [random.choice(ms)] + [random.choice(Ns) for k in xrange(K-1)] random.shuffle(o) Outputs += [o] # Get top m nodes def topm(d): vs = [(v,k) for (k,v) in d.iteritems()] vs.sort() vs.reverse() top = [k for (v,k) in vs][:m] top.sort() return top def xuniqueCombinations(items, n): if n==0: yield [] else: for i in xrange(len(items)): for cc in xuniqueCombinations(items[i+1:],n-1): yield [items[i]]+cc Cands = list(xuniqueCombinations(Ns,m)) # Statistical disclusure round after round counts = {} for n in Ns: counts[n] = 0 print "\t%s\t%s\t%s\t%s" % ("Round Receivers", "SDA", "SDA_error", "Hitting set") ix = 0 for o in Outputs: ix +=1 for r in o: counts[r] += 1 # SDA part SDAbest = topm(counts) SADerror = len(set(SDAbest) - set(ms)) # Disclosure / Hitting set part Cands = [c for c in Cands if len(set(c) & set(o)) >0] CandsL = len(Cands) print "%s\t%s\t%s\t%s\t%s" % (ix, o, SDAbest, SADerror, CandsL)