def pk_from_dict(dict_object): pk = PublicKey() pk.g = dict_object['p'] pk.q = dict_object['q'] pk.g = dict_object['g'] pk.y = dict_object['y'] return pk
def get_generic_election(cls, nr_candidates, max_choices, pk): elections = cls._generic_elections if (max_choices is None or max_choices <= 0 or max_choices > nr_candidates): max_choices = nr_candidates key = (nr_candidates, max_choices, pk.p, pk.g, pk.q, pk.y) if key in elections: return elections[key] candidates = ["Candidate #%d" % x for x in xrange(nr_candidates)] public_key = PublicKey() public_key.p = pk.p public_key.g = pk.g public_key.q = pk.q public_key.y = pk.y election = Election(candidates, max_choices=max_choices, public_key=public_key) elections[key] = election return election
def get_generic_election(cls, nr_candidates, max_choices, pk): elections = cls._generic_elections if (max_choices is None or max_choices <= 0 or max_choices > nr_candidates): max_choices = nr_candidates key = (nr_candidates, max_choices, pk.p, pk.g, pk.q, pk.y) if key in elections: return elections[key] candidates = ["Candidate #%d" % x for x in xrange(nr_candidates)] public_key = PublicKey() public_key.p = pk.p public_key.g = pk.g public_key.q = pk.q public_key.y = pk.y election = Election(candidates, max_choices = max_choices, public_key = public_key) elections[key] = election return election
Answers: [0] """ _default_crypto = Crypto() # from helios/views.py from cryptosystems import c2048 as crypto p, q, g, x, y = crypto() _default_crypto.p = p _default_crypto.q = q _default_crypto.g = g _default_public_key = PublicKey() _default_public_key.p = _default_crypto.p _default_public_key.q = _default_crypto.q _default_public_key.g = _default_crypto.g _default_secret_key = SecretKey() _default_secret_key.x = x _default_secret_key.pk = _default_public_key _default_public_key.y = y def get_timestamp(): return datetime.strftime(datetime.utcnow(), "%Y-%m-%dT%H:%M:%S.%fZ") def get_choice_params(nr_choices, nr_candidates=None, max_choices=None): if nr_candidates is None: nr_candidates = nr_choices
""" _default_crypto = Crypto() # from helios/views.py from cryptosystems import c2048 as crypto p, q, g, x, y = crypto() _default_crypto.p = p _default_crypto.q = q _default_crypto.g = g _default_public_key = PublicKey() _default_public_key.p = _default_crypto.p _default_public_key.q = _default_crypto.q _default_public_key.g = _default_crypto.g _default_secret_key = SecretKey() _default_secret_key.x = x _default_secret_key.pk = _default_public_key _default_public_key.y = y def get_timestamp(): return datetime.strftime(datetime.utcnow(), "%Y-%m-%dT%H:%M:%S.%fZ") def get_choice_params(nr_choices, nr_candidates=None, max_choices=None): if nr_candidates is None: nr_candidates = nr_choices