This repository has been archived on 2022-08-01. You can view files and clone it, but cannot push or open issues or pull requests.
DEMOS2/static/js/vote_audit.js

34 lines
1.5 KiB
JavaScript
Raw Normal View History

2018-08-16 21:17:16 +00:00
$('#begin-test').click(function() {
var ballot = JSON.parse(sjcl.decrypt($('#SK').val(), $('#ballot').text()));
2018-08-29 13:29:27 +00:00
var votes = ballot['encryptedVotes'];
2018-08-16 21:17:16 +00:00
$('#ballot-content').text(JSON.stringify(votes));
2018-08-29 13:29:27 +00:00
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";
}
2018-08-16 21:17:16 +00:00
2018-08-29 13:29:27 +00:00
// 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 ");
});
});
2018-08-16 21:17:16 +00:00
});