Example #1
0
 def get_choices(self, encoded, nr_answers, answers=None, params=None):
     max_encoded = core.gamma_encoding_max(nr_answers)
     if encoded > max_encoded:
         choices = []
     else:
         selection = core.gamma_decode(encoded, nr_answers)
         choices = to_absolute_answers(selection, nr_answers)
     return choices
Example #2
0
 def get_choices(self, encoded, nr_answers, answers=None, params=None):
     max_encoded = core.gamma_encoding_max(nr_answers)
     if encoded > max_encoded:
         choices = []
     else:
         selection = core.gamma_decode(encoded, nr_answers)
         choices = to_absolute_answers(selection, nr_answers)
     return choices
Example #3
0
def main_verify(sigfile, randomness=None, plaintext=None):
    with open(sigfile) as f:
        signature = f.read()

    vote_info = verify_vote_signature(signature)
    signed_vote, crypto, trustees, candidates, comments = vote_info

    eb = signed_vote['encrypted_ballot']
    public = eb['public']
    modulus, generator, order = crypto
    beta = eb['beta']
    print 'VERIFIED: Authentic Signature'
    if randomness is None:
        return

    nr_candidates = len(candidates)
    encoded = decrypt_with_randomness(modulus, generator, order,
                                      public, beta, randomness)
    if plaintext is not None:
        if plaintext != encoded:
            print 'FAILED: Plaintext Mismatch'

        ct = encrypt(plaintext, modulus, generator, order, randomness)
        _alpha, _beta, _randomness = ct
        alpha = eb['alpha']
        if (alpha, beta) != (_alpha, _beta):
            print 'FAILED: Invalid Encryption'

    max_encoded = gamma_encoding_max(nr_candidates) + 1
    print "plaintext:       %d" % encoded
    print "max plaintext:   %d" % max_encoded
    if encoded > max_encoded:
        print "FAILED: Invalid Vote. Cannot decode."
        return

    selection = gamma_decode(encoded, nr_candidates)
    choices = to_absolute_answers(selection, nr_candidates)
    print ""
    for i, o in enumerate(choices):
        print "%d: [%d] %s" % (i, o, candidates[o])
    print ""
Example #4
0
def main_verify(sigfile, randomness=None, plaintext=None):
    with open(sigfile) as f:
        signature = f.read()

    vote_info = verify_vote_signature(signature)
    signed_vote, crypto, trustees, candidates, comments = vote_info

    eb = signed_vote['encrypted_ballot']
    public = eb['public']
    modulus, generator, order = crypto
    beta = eb['beta']
    print 'VERIFIED: Authentic Signature'
    if randomness is None:
        return

    nr_candidates = len(candidates)
    encoded = decrypt_with_randomness(modulus, generator, order,
                                      public, beta, randomness)
    if plaintext is not None:
        if plaintext != encoded:
            print 'FAILED: Plaintext Mismatch'

        ct = encrypt(plaintext, modulus, generator, order, randomness)
        _alpha, _beta, _randomness = ct
        alpha = eb['alpha']
        if (alpha, beta) != (_alpha, _beta):
            print 'FAILED: Invalid Encryption'

    max_encoded = gamma_encoding_max(nr_candidates) + 1
    print "plaintext:       %d" % encoded
    print "max plaintext:   %d" % max_encoded
    if encoded > max_encoded:
        print "FAILED: Invalid Vote. Cannot decode."
        return

    selection = gamma_decode(encoded, nr_candidates)
    choices = to_absolute_answers(selection, nr_candidates)
    print ""
    for i, o in enumerate(choices):
        print "%d: [%d] %s" % (i, o, candidates[o])
    print ""