From cf2bf7de224b3ff34d7e8248839a312d18db4ffe Mon Sep 17 00:00:00 2001 From: Rumperuu Date: Tue, 11 Sep 2018 08:31:47 +0100 Subject: [PATCH] Committing --- Node/index.js | 2 +- Node/package.json | 3 ++- static/js/create-event-poll.js | 2 +- static/js/vote_audit.js | 38 ++++++++++++++++++++++++++-------- 4 files changed, 33 insertions(+), 12 deletions(-) diff --git a/Node/index.js b/Node/index.js index 9df424b..f78862f 100755 --- a/Node/index.js +++ b/Node/index.js @@ -374,7 +374,7 @@ encrypt = function(params,PK, m) { C2 = ctx.PAIR.G1mul(PK,r); C2.mul(r); C2.add(gM); - + return{ C1:C1, C2:C2 diff --git a/Node/package.json b/Node/package.json index 9e11f20..96d92d7 100644 --- a/Node/package.json +++ b/Node/package.json @@ -20,6 +20,7 @@ "atob": "^2.1.2", "body-parser": "^1.18.3", "express": "^4.16.3", - "milagro-crypto-js": "git+https://github.com/milagro-crypto/milagro-crypto-js.git" + "milagro-crypto-js": "git+https://github.com/milagro-crypto/milagro-crypto-js.git", + "npm": "^6.4.1" } } diff --git a/static/js/create-event-poll.js b/static/js/create-event-poll.js index fa41893..53a773c 100755 --- a/static/js/create-event-poll.js +++ b/static/js/create-event-poll.js @@ -244,7 +244,7 @@ function isEventTimingsValid() { var end_dateObj = new Date(end_date_time); // Ensure that the start date is before the end date and that the end date is after the start date - if(!(start_dateObj < end_dateObj && end_dateObj > start_dateObj)) { + if(!(start_date_time < end_date_time)) { checkAndAddError({ error: "The start date must be before the end date and the end after the start date.", helpBlockId: "event-timings-error-block" diff --git a/static/js/vote_audit.js b/static/js/vote_audit.js index 9e33fc1..d6e9c78 100644 --- a/static/js/vote_audit.js +++ b/static/js/vote_audit.js @@ -1,4 +1,19 @@ +function getBytes(arr) { + for(var i = 0; i < arr.length; i++) { + arr[i] = parseInt(arr[i]); + } + + return new Uint8Array(arr); +} + $('#begin-test').click(function() { + var ctx = new CTX("BN254CX"); + var ciphertext = { + C1: null, + C2: null, + r: null + } + var ballot = JSON.parse(sjcl.decrypt($('#SK').val(), $('#ballot').text())); var votes = ballot['encryptedVotes']; @@ -10,21 +25,26 @@ $('#begin-test').click(function() { 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)... + // For each encrypted fragment within the vote (i.e. the encoded vote for one 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"; - } + var C1 = getBytes(fragment['C1'].split(",")); + var C2 = getBytes(fragment['C2'].split(",")); + var r = getBytes(fragment['r'].split(",")); + + ciphertext.C1 = new ctx.ECP.fromBytes(C1); + ciphertext.C2 = new ctx.ECP.fromBytes(C2); + ciphertext.r = new ctx.BIG.fromBytes(r); + + // For each pair of C1,C2 values (i.e. one ballot's ciphertext) and the randomness used in its encryption r, + // test whether C2/(C1)^r = g^0 or g^1, and record g's exponent. + var m = ciphertext.C2 / Math.pow(ciphertext.C1, ciphertext.r); + console.log("m = "+m); + 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.