-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
176 lines (158 loc) · 6.92 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jsencrypt/3.2.0/jsencrypt.min.js"
integrity="sha512-+81yWICnHhrOvwt+zssByewxN2EDLJGUyC8Q2dKyYNClFMMe4RONxwLEmSAm+e/ZpxTC1jgKpeyijAY1MhLObQ=="
crossorigin="anonymous"></script>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<title>Final Results</title>
<!-- Bootstrap CSS file -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css">
</head>
<body>
<div id="keys">
<h1 class="text-center m-4">Vote Decryption</h1>
<h3 class="small text-muted m-3">To begin the vote count, please provide the appropriate keys.</h3><br>
<h5>Tallier 1</h5>
<input type="text" id="key1" placeholder="Private Key 1" class="m-3">
<h5>Tallier 2</h5>
<input type="text" id="key2" placeholder="Private Key 2" class="m-3">
<h5>Tallier 3</h5>
<input type="text" id="key3" placeholder="Private Key 3" class="m-3">
<h5>Tallier 4</h5>
<input type="text" id="key4" placeholder="Private Key 4" class="m-3">
<button type="button" class="btn btn-primary" id="validate">Decrypt Ballot</button>
</div>
<div id="content" style="display: none">
<h1 class="text-center m-4">Computed Results</h1>
<main id="votegraph">
<div id="piechart"></div>
</main>
<h2>Audit Log</h2>
<pre id="logger"></pre>
</div>
<!-- JS files: jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js"></script>
</body>
<style>
#content {
display: flex;
flex-direction: column;
align-items: center;
}
#logger {
text-align: left;
}
#keys {
display: flex;
flex-direction: column;
align-items: center;
}
</style>
<script>
</script>
<script>
function countstories(g) {
let names = new Set(g);
let elem = {}
let elem2 = [["Candidate", "Votes"]]
names.forEach(function (w) {
elem[w] = 0
})
g.forEach(function (e) {
elem[e]++;
})
// for (let i = 0; i < g.length; i++) {
// for (let j = 0; j < elem.length; j++) {
// if (elem[j][0] == g[i]) {
// if (elem[j][1] == null) {
// elem[j][1] = 1
// } else {
// elem[j][i] = ++elem[j][i];
// }
// }
// }
//
// }
for (const [key, value] of Object.entries(elem)) {
elem2.push([key, value])
}
return elem2
}
let prikey = null;
let encvotes = []
let decvote = []
// Fetch votes
$(document).ready(function () {
let iamkey = "eyJraWQiOiIyMDIxMDQyMDE4MzYiLCJhbGciOiJSUzI1NiJ9.eyJpYW1faWQiOiJpYW0tU2VydmljZUlkLTdlZjcyMjEwLTdmNDEtNGMzOC05OGUzLTQxMTk0MzBkMWFlNiIsImlkIjoiaWFtLVNlcnZpY2VJZC03ZWY3MjIxMC03ZjQxLTRjMzgtOThlMy00MTE5NDMwZDFhZTYiLCJyZWFsbWlkIjoiaWFtIiwianRpIjoiYzVhMTU3MTQtMGM2My00MTczLTljYWQtNWM5NzNmMzUyNTMxIiwiaWRlbnRpZmllciI6IlNlcnZpY2VJZC03ZWY3MjIxMC03ZjQxLTRj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syAuhmNJw-9gBUWPVnW1ElW8RmkywuwaCj_QfF83Q"
let auth = "Bearer " + iamkey
var settings = {
"url": "https://55495ede-9b8a-466e-a626-c67d98f2ca9f-bluemix.cloudant.com/voters/_all_docs?include_docs=true",
"method": "GET",
"timeout": 0,
"headers": {
"Authorization": auth
},
};
let datadump = null;
$.ajax(settings).done(function (response) {
console.log(response)
for (let i = 0; i < response.rows.length; i++) {
decvote.push(response.rows[i].doc.vote);
}
console.log(encvotes)
});
})
$("#validate").click(function () {
let key1 = $("#key1").val();
let key2 = $("#key2").val();
let key3 = $("#key3").val();
let key4 = $("#key4").val();
// prikey = ` `
prikey = key1 + key2 + key3 + key4
console.log(prikey);
$("#keys").toggle()
$("#content").toggle()
// var decrypt = new JSEncrypt();
// decrypt.setPrivateKey(prikey)
// encvotes.forEach(function (e) {
// var uncrypted = decrypt.decrypt(e);
// decvote.push(uncrypted)
// console.log(uncrypted);
//
//
drawChart(countstories(decvote));
})
})
//fetch votes
</script>
<script type="text/javascript">
let logs = []
async function getLogs() {
$.get("http://127.0.0.1:8080/getLog", function (response) {
console.log(response)
logs = response
logs.forEach(function (e) {
if (e == "0") throw DOMException;
$("#logger").append("[BLOCKCHAIN LOG @" + new Date($.now()) + "]: Vote processed with txid: " + e + ".\n")
})
})
}
getLogs()
// Load google charts
google.charts.load('current', {'packages': ['corechart']});
// Draw the chart and set the chart values
function drawChart(datas) {
var data = google.visualization.arrayToDataTable(datas);
// Optional; add a title and set the width and height of the chart
var options = {'title': 'Vote Counting Results', 'width': 650, 'height': 500};
// Display the chart inside the <div> element with id="piechart"
var chart = new google.visualization.ColumnChart(document.getElementById('piechart'));
chart.draw(data, options);
}
</script>
</html>