-
Notifications
You must be signed in to change notification settings - Fork 0
/
crypto.py
30 lines (22 loc) · 968 Bytes
/
crypto.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# This file contains basic election cryptographic related setup.
from candidates import NUMBER_OF_CANDIDATES, NUMBER_OF_MARKS
from cryptosystem.encryption import *
from cryptosystem.decryption import *
from cryptosystem.cryptosystem_setup import *
from aggregator import *
class Crypto(object):
# Constructor.
def __init__(self):
keys = generate_keys()
self.public_key = keys[:2]
self.private_key = keys[2:4]
self.encryptor = Encryptor(self.public_key)
self.decryptor = Decryptor(self.public_key, self.private_key)
self.aggregator = Aggregator(self.encryptor, self.decryptor, NUMBER_OF_CANDIDATES, NUMBER_OF_MARKS)
# Adds new matrix of votes.
def process(self, data):
data = [[int(it) for it in row.split(',')] for row in data.split('\n')]
self.aggregator.add_vote(data)
# Aggregates and returns the winner.
def aggregate(self):
return self.aggregator.aggregate()