コード例 #1
0
def votingResults(votes):
    """Gets the results of an election.
	
	Gets the results of an election where the users selected 0 for no, and 1 for yes.
	It gets the amount of votes for no and yes by decrypting each of the votes.
	
	Args:
	    votes: List of the votes of the election.
	
	Returns:
	    A dictionary with the results of the election:
	    {
			"yes": 1000, 
			"no": 9999
		}
	
	Raises:
	    Type: Description.
	"""
    yes, no = 0, 0
    for vote in votes:
        value = cryptok.paillier_dec(vote, N, phi_N, N_power_2, inverse_phy_N)
        if value == 0:
            no += 1
        elif value == 1:
            yes += 1
    return {"yes": yes, "no": no}
コード例 #2
0
def votingResults(votes):
	"""Gets the results of an election.
	
	Gets the results of an election where the users selected 0 for no, and 1 for yes.
	It gets the amount of votes for no and yes by decrypting each of the votes.
	
	Args:
	    votes: List of the votes of the election.
	
	Returns:
	    A dictionary with the results of the election:
	    {
			"yes": 1000, 
			"no": 9999
		}
	
	Raises:
	    Type: Description.
	"""
	yes, no = 0, 0
	for vote in votes:
		value = cryptok.paillier_dec(vote, N, phi_N, N_power_2, inverse_phy_N)
		if value == 0:
			no+=1
		elif value == 1:
			yes+=1
	return {
		"yes": yes, 
		"no": no
	}
コード例 #3
0
    yes, no = 0, 0
    for vote in votes:
        value = cryptok.paillier_dec(vote, N, phi_N, N_power_2, inverse_phy_N)
        if value == 0:
            no += 1
        elif value == 1:
            yes += 1
    return {"yes": yes, "no": no}


# Read the votes from the files
votes = readVotes('data/paillier-exercise.txt')
L = len(votes)
print("Total votes(L): ", L)

# Get the election results without decrypting all the votes
aggregation = cryptok.paillier_aggregation(votes, N, N_power_2)
dec_aggregation = cryptok.paillier_dec(aggregation, N, phi_N, N_power_2,
                                       inverse_phy_N)
print("paillier_dec(aggregation): ", dec_aggregation)
if dec_aggregation > L / 2:
    print("The winner is YES")
elif dec_aggregation < L / 2:
    print("The winner is NO")
else:
    print("TIE")

# Get the election results by decrypting each of the votes.
results = votingResults(votes)
print("results: ", results)
コード例 #4
0
		if value == 0:
			no+=1
		elif value == 1:
			yes+=1
	return {
		"yes": yes, 
		"no": no
	}

# Read the votes from the files
votes = readVotes('data/paillier-exercise.txt')
L = len(votes)
print("Total votes(L): ", L)

# Get the election results without decrypting all the votes
aggregation = cryptok.paillier_aggregation(votes, N, N_power_2)
dec_aggregation = cryptok.paillier_dec(aggregation, N,phi_N, N_power_2, inverse_phy_N)
print("paillier_dec(aggregation): ", dec_aggregation)
if dec_aggregation > L / 2:
	print("The winner is YES")
elif dec_aggregation < L / 2:
	print("The winner is NO")
else: 
	print("TIE")

# Get the election results by decrypting each of the votes.
results = votingResults(votes)
print("results: ", results)