From 9ea59723a52a6184ef8ee14607ff717e38c7bdfc Mon Sep 17 00:00:00 2001 From: Rumperuu Date: Wed, 29 Aug 2018 14:29:27 +0100 Subject: [PATCH] I really ought to be using branches --- allauthdemo/polls/views.py | 6 +++--- static/js/event_vote.js | 4 +++- static/js/vote_audit.js | 43 ++++++++++++++++++++++++++------------ 3 files changed, 36 insertions(+), 17 deletions(-) diff --git a/allauthdemo/polls/views.py b/allauthdemo/polls/views.py index 9694e6d..c498fbe 100755 --- a/allauthdemo/polls/views.py +++ b/allauthdemo/polls/views.py @@ -113,11 +113,11 @@ def edit_poll(request, event_id, poll_id): def vote_audit(request): - encryptedBallot = get_object_or_404(EncBallot, handle=''+urllib.quote_plus(request.GET.get('handle', None))) + encrypted_ballot = get_object_or_404(EncBallot, handle=''+urllib.quote_plus(request.GET.get('handle', None))) return render(request, "polls/vote_audit.html", { - "ballot": encryptedBallot.ballot + "ballot": encrypted_ballot.ballot }) @@ -192,7 +192,7 @@ def event_vote(request, event_id, poll_id): # Adds or replaces the encrypted un-submitted ballot to the database for the auditor app to pick up later if EncBallot.objects.filter(handle=handle_json).exists(): b = EncBallot.objects.get(handle=handle_json) - b.ballot = ballot_json + b.ballot = enc_ballot_json b.save() else: b = EncBallot(handle=handle_json, ballot=enc_ballot_json) diff --git a/static/js/event_vote.js b/static/js/event_vote.js index a68ad21..05946f5 100644 --- a/static/js/event_vote.js +++ b/static/js/event_vote.js @@ -319,7 +319,6 @@ function showFirstQRCode(ballotA, ballotB) { footer.prepend(nextButton); - modalDialog.modal('show'); $('#next-button').click(function(e) { @@ -450,6 +449,9 @@ function onAfterBallotSend(ballotID, SK) { closeButton.removeClass('btn-danger'); closeButton.addClass('btn-success'); closeButton.text("Close"); + if(POLL_NUM == POLL_COUNT) { + $('#next-button').hide(); + } modalDialog.modal('show'); } \ No newline at end of file diff --git a/static/js/vote_audit.js b/static/js/vote_audit.js index d82f9bc..9e33fc1 100644 --- a/static/js/vote_audit.js +++ b/static/js/vote_audit.js @@ -1,17 +1,34 @@ $('#begin-test').click(function() { var ballot = JSON.parse(sjcl.decrypt($('#SK').val(), $('#ballot').text())); - var votes = ballot['encryptedVotes'][0]['fragments']; - $('#ballot-content').text(JSON.stringify(votes)); - var option = 0; - votes.forEach(function(cT) { - option++; - var encoding = ""; - for (var i = 0; i < cT['C1'].length; i++) { - cipherText = "("+cT['C1']+","+cT['C2']+")"; - var m = cT['C2'][i] / Math.pow(cT['C1'][i], cT['r'][i]); - encoding += (m) ? "1" : "0"; - } - $('#ballot-result').text($('#ballot-result').text() + "\n\nOption "+option+": "+encoding); - }) + var votes = ballot['encryptedVotes']; + $('#ballot-content').text(JSON.stringify(votes)); + var voteNum = 0, optionNum = 0; + + // For each encrypted vote within the ballot... + votes.forEach(function(vote) { + voteNum++; + $('#ballot-result').text($('#ballot-result').text() + "Vote " + voteNum + ": \n "); + + // For each encrypted fragment within the vote (i.e. the presence of a vote for each option)... + vote['fragments'].forEach(function(fragment) { + optionNum++; + $('#ballot-result').text($('#ballot-result').text() + "Option " + optionNum + ": \n "); + + var encoding = ""; + console.log(fragment); + + // For each pair of values in C1 and C2 and the randomness r, test whether C2/(C1)^r = g^0 or g^1, and + // record g's exponent. + for (var i = 0; i < fragment['C1'].length; i++) { + cipherText = "("+fragment['C1']+","+fragment['C2']+")"; + var m = fragment['C2'][i] / Math.pow(fragment['C1'][i], fragment['r'][i]); + encoding += (m) ? "1" : "0"; + } + + // Somehow, this string of 1s and 0s here needs to become _one_ 1 or 0 to signify whether the option was + // voted for or not. + $('#ballot-result').text($('#ballot-result').text() + encoding + "\n "); + }); + }); }); \ No newline at end of file