Committing

This commit is contained in:
Rumperuu 2018-09-11 08:31:47 +01:00
parent 7e601a25e3
commit cf2bf7de22
4 changed files with 33 additions and 12 deletions

View File

@ -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

View File

@ -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"
}
}

View File

@ -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"

View File

@ -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.