Riskless/templates/index.html

381 lines
14 KiB
HTML
Raw Normal View History

2022-12-26 14:13:02 +00:00
<!DOCTYPE html>
2022-12-29 14:11:18 +00:00
<html lang="en">
2023-02-17 12:46:21 +00:00
<head>
<title>Riskless</title>
2022-12-29 14:11:18 +00:00
2023-02-17 12:46:21 +00:00
<link href="{{ url_for('static', filename='css/style.css') }}" rel="stylesheet">
2022-12-29 14:11:18 +00:00
2023-02-17 12:46:21 +00:00
<script src="https://cdn.socket.io/4.5.4/socket.io.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.1.1/crypto-js.min.js"></script>
2023-04-15 13:28:13 +00:00
<script src="{{ url_for('static', filename='js/lz-string.js') }}"></script>
<script src="{{ url_for('static', filename='js/sha3.js') }}"></script>
<script src="{{ url_for('static', filename='js/modules/interface/main.js') }}" type="module"></script>
<script src="{{ url_for('static', filename='js/modules/crypto/main.js') }}" type="module"></script>
2023-02-17 12:46:21 +00:00
</head>
<body>
2023-02-18 15:12:06 +00:00
<div id="modal" class="hidden modal">
2023-02-17 12:46:21 +00:00
<div class="modal-content">
<div>
<label>
Amount
<input type="number" class="amount">
</label>
</div>
<div>
<label>
Target
<select class="target"></select>
</label>
</div>
<div class="button-row">
<button class="submit-modal">Submit</button>
<button class="cancel-modal">Cancel</button>
</div>
</div>
</div>
2023-02-18 15:12:06 +00:00
<div id="defense-modal" class="hidden modal">
<div class="modal-content">
<div>
<h2>Defending region <span class="region-tag">R</span></h2>
<label>
Defense amount
<input type="number" class="amount">
</label>
</div>
<button class="submit-modal">Submit</button>
</div>
</div>
<div id="players-div">
<strong>Players</strong>
<ul id="playerList">
</ul>
<button id="shuffleColors">Shuffle colours</button>
</div>
<div id="remaining-reinforcements">
</div>
2023-02-08 15:52:02 +00:00
<div id="info">
</div>
2023-02-06 12:30:24 +00:00
<div id="map">
<svg id="map-back" viewBox="-520 -520 1000 1000" width="1000" height="1000">
<line x1="0" y1="0" x2="160" y2="0" stroke="black"></line>
<line x1="160" y1="0" x2="260" y2="0" stroke="black"></line>
<line x1="160" y1="0" x2="220" y2="-200" stroke="black"></line>
<line x1="280" y1="0" x2="220" y2="-200" stroke="black"></line>
<line x1="220" y1="-200" x2="380" y2="-200" stroke="black"></line>
<line x1="220" y1="-200" x2="-40" y2="-140" stroke="black"></line>
<line x1="0" y1="0" x2="-40" y2="-140" stroke="black"></line>
<line x1="0" y1="0" x2="-40" y2="140" stroke="black"></line>
<line x1="-280" y1="80" x2="-40" y2="140" stroke="black"></line>
<line x1="-280" y1="-80" x2="-40" y2="-140" stroke="black"></line>
<line x1="-280" y1="80" x2="-180" y2="0" stroke="black"></line>
<line x1="-280" y1="-80" x2="-180" y2="0" stroke="black"></line>
<line x1="-180" y1="0" x2="-40" y2="140" stroke="black"></line>
<path d="M -280 80 Q -360 0 -280 -80" stroke="black" fill="transparent"></path>
</svg>
2023-02-06 13:03:25 +00:00
<div class="node east" data-name="A" style="left: 280px;">
2023-02-16 09:38:03 +00:00
<div class="strength"></div>
2023-02-06 12:30:24 +00:00
<div class="label">A</div>
<div class="actions">
2023-03-13 14:52:14 +00:00
<button class="claim">Claim</button>
2023-02-16 09:38:03 +00:00
<button class="reinforce">Reinf.</button>
<button class="attack">Attack</button>
<button class="fortify">Fortify</button>
</div>
2023-02-06 12:30:24 +00:00
</div>
2023-02-06 13:03:25 +00:00
<div class="node east" data-name="B" style="left: 160px;">
2023-02-16 09:38:03 +00:00
<div class="strength"></div>
2023-02-06 12:30:24 +00:00
<div class="label">B</div>
<div class="actions">
2023-03-13 14:52:14 +00:00
<button class="claim">Claim</button>
2023-02-16 09:38:03 +00:00
<button class="reinforce">Reinf.</button>
<button class="attack">Attack</button>
<button class="fortify">Fortify</button>
</div>
2023-02-06 12:30:24 +00:00
</div>
2023-02-06 13:03:25 +00:00
<div class="node east" data-name="C" style="left: 220px; top: -200px;">
2023-02-16 09:38:03 +00:00
<div class="strength"></div>
2023-02-06 12:30:24 +00:00
<div class="label">C</div>
<div class="actions">
2023-03-13 14:52:14 +00:00
<button class="claim">Claim</button>
2023-02-16 09:38:03 +00:00
<button class="reinforce">Reinf.</button>
<button class="attack">Attack</button>
<button class="fortify">Fortify</button>
</div>
2023-02-06 12:30:24 +00:00
</div>
2023-02-06 13:03:25 +00:00
<div class="node east" data-name="D" style="left: 380px; top: -200px;">
2023-02-16 09:38:03 +00:00
<div class="strength"></div>
2023-02-06 12:30:24 +00:00
<div class="label">D</div>
<div class="actions">
2023-03-13 14:52:14 +00:00
<button class="claim">Claim</button>
2023-02-16 09:38:03 +00:00
<button class="reinforce">Reinf.</button>
<button class="attack">Attack</button>
<button class="fortify">Fortify</button>
</div>
2023-02-06 12:30:24 +00:00
</div>
2023-02-06 13:03:25 +00:00
<div class="node west" data-name="E" style="left: -40px; top: 140px;">
2023-02-16 09:38:03 +00:00
<div class="strength"></div>
2023-02-06 12:30:24 +00:00
<div class="label">E</div>
<div class="actions">
2023-03-13 14:52:14 +00:00
<button class="claim">Claim</button>
2023-02-16 09:38:03 +00:00
<button class="reinforce">Reinf.</button>
<button class="attack">Attack</button>
<button class="fortify">Fortify</button>
</div>
2023-02-06 12:30:24 +00:00
</div>
2023-02-06 13:03:25 +00:00
<div class="node west" data-name="F" style="left: -40px; top: -140px;">
2023-02-16 09:38:03 +00:00
<div class="strength"></div>
2023-02-06 12:30:24 +00:00
<div class="label">F</div>
<div class="actions">
2023-03-13 14:52:14 +00:00
<button class="claim">Claim</button>
2023-02-16 09:38:03 +00:00
<button class="reinforce">Reinf.</button>
<button class="attack">Attack</button>
<button class="fortify">Fortify</button>
</div>
2023-02-06 12:30:24 +00:00
</div>
2023-02-06 13:03:25 +00:00
<div class="node west" data-name="G" style="left: -280px; top: -80px;">
2023-02-16 09:38:03 +00:00
<div class="strength"></div>
2023-02-06 12:30:24 +00:00
<div class="label">G</div>
<div class="actions">
2023-03-13 14:52:14 +00:00
<button class="claim">Claim</button>
2023-02-16 09:38:03 +00:00
<button class="reinforce">Reinf.</button>
<button class="attack">Attack</button>
<button class="fortify">Fortify</button>
</div>
2023-02-06 12:30:24 +00:00
</div>
2023-02-06 13:03:25 +00:00
<div class="node west" data-name="H" style="left: -280px; top: 80px;">
2023-02-16 09:38:03 +00:00
<div class="strength"></div>
2023-02-06 12:30:24 +00:00
<div class="label">H</div>
<div class="actions">
2023-03-13 14:52:14 +00:00
<button class="claim">Claim</button>
2023-02-16 09:38:03 +00:00
<button class="reinforce">Reinf.</button>
<button class="attack">Attack</button>
<button class="fortify">Fortify</button>
</div>
2023-02-06 12:30:24 +00:00
</div>
2023-02-06 13:03:25 +00:00
<div class="node west" data-name="I" style="left: -180px;">
2023-02-16 09:38:03 +00:00
<div class="strength"></div>
2023-02-06 12:30:24 +00:00
<div class="label">I</div>
<div class="actions">
2023-03-13 14:52:14 +00:00
<button class="claim">Claim</button>
2023-02-16 09:38:03 +00:00
<button class="reinforce">Reinf.</button>
<button class="attack">Attack</button>
<button class="fortify">Fortify</button>
</div>
2023-02-06 12:30:24 +00:00
</div>
2023-02-06 13:03:25 +00:00
<div class="node east" data-name="J" style="">
2023-02-16 09:38:03 +00:00
<div class="strength"></div>
2023-02-06 12:30:24 +00:00
<div class="label">J</div>
<div class="actions">
2023-03-13 14:52:14 +00:00
<button class="claim">Claim</button>
2023-02-16 09:38:03 +00:00
<button class="reinforce">Reinf.</button>
<button class="attack">Attack</button>
<button class="fortify">Fortify</button>
</div>
2023-02-06 12:30:24 +00:00
</div>
</div>
<div id="ready">
<button id="ready-button">Not ready</button>
2023-02-16 09:38:03 +00:00
<button id="end-turn" class="hidden">End Turn</button>
</div>
2023-04-06 20:33:15 +00:00
<!-- Benchmarking script -->
<script>
function RSABench() {
console.log("Warming up")
2023-04-15 13:28:13 +00:00
const ROUNDS = 250;
2023-04-06 20:33:15 +00:00
for (let i = 0n; i < 100n; i++) {
window.rsa.pubKey.encrypt(i);
}
console.log("Benching")
performance.mark("rsa-start")
2023-04-15 13:28:13 +00:00
for (let i = 0n; i < BigInt(ROUNDS); i++) {
2023-04-06 20:33:15 +00:00
window.rsa.pubKey.encrypt(i);
}
performance.mark("rsa-end")
2023-04-15 13:28:13 +00:00
console.log(`Bench done. Time per encrypt: ${performance.measure("rsa-duration", "rsa-start", "rsa-end").duration / ROUNDS}`)
2023-04-06 20:33:15 +00:00
}
function PaillierBench() {
console.log("Warming up")
2023-04-15 13:28:13 +00:00
const ROUNDS = 250
2023-04-06 20:33:15 +00:00
for (let i = 0n; i < 100n; i++) {
window.paillier.pubKey.encrypt(i);
}
console.log("Benching")
performance.mark("paillier-start")
2023-04-15 13:28:13 +00:00
for (let i = 0n; i < BigInt(ROUNDS); i++) {
2023-04-06 20:33:15 +00:00
window.paillier.pubKey.encrypt(i);
}
performance.mark("paillier-end")
2023-04-15 13:28:13 +00:00
console.log(`Bench done. Time per encrypt: ${performance.measure("paillier-duration", "paillier-start", "paillier-end").duration / ROUNDS}`)
}
function ZeroProofBench() {
console.log("Warming up")
const cipherText = paillier.pubKey.encrypt(0n)
const ROUNDS = 20;
for (let i = 0; i < 5; i++) {
cipherText.proveNI();
}
console.log("Benching")
performance.mark("paillier-start")
for (let i = 0; i < ROUNDS; i++) {
cipherText.proveNI()
}
performance.mark("paillier-end")
console.log(`Bench done. Time per proof: ${performance.measure("paillier-duration", "paillier-start", "paillier-end").duration / ROUNDS}`)
}
function ZeroProofVerifierBench() {
console.log("Warming up")
const ROUNDS = 20
const cipherText = paillier.pubKey.encrypt(1n)
const readOnly = cipherText.asReadOnlyCiphertext();
const proof = cipherText.proveNI()
for (let i = 0; i < 5; i++) {
readOnly.verifyNI(proof)
}
console.log("Benching")
performance.mark("paillier-start")
for (let i = 0; i < ROUNDS; i++) {
readOnly.verifyNI(proof)
}
performance.mark("paillier-end")
console.log(`Bench done. Time per verification: ${performance.measure("paillier-duration", "paillier-start", "paillier-end").duration / ROUNDS}`)
}
function Protocol4Bench() {
console.log("Warming up")
const regions = {
A: paillier.pubKey.encrypt(0n),
B: paillier.pubKey.encrypt(1n),
C: paillier.pubKey.encrypt(0n),
D: paillier.pubKey.encrypt(0n),
E: paillier.pubKey.encrypt(0n)
}
const ROUNDS = 20;
for (let i = 0; i < 5; i++) {
proveRegions(regions)
}
console.log("Benching")
performance.mark("paillier-start")
for (let i = 0; i < ROUNDS; i++) {
proveRegions(regions)
}
performance.mark("paillier-end")
console.log(`Bench done. Time per proof: ${performance.measure("paillier-duration", "paillier-start", "paillier-end").duration / ROUNDS}`)
}
function Protocol4VerifierBench() {
console.log("Warming up")
const ROUNDS = 20;
const regions = {
A: paillier.pubKey.encrypt(0n),
B: paillier.pubKey.encrypt(1n),
C: paillier.pubKey.encrypt(0n),
D: paillier.pubKey.encrypt(0n),
E: paillier.pubKey.encrypt(0n)
}
let proof = proveRegions(regions)
for (let i = 0; i < 5; i++) {
verifyRegions(proof, paillier.pubKey)
}
console.log("Benching")
performance.mark("paillier-start")
for (let i = 0; i < ROUNDS; i++) {
verifyRegions(proof, paillier.pubKey)
}
performance.mark("paillier-end")
console.log(`Bench done. Time per verification: ${performance.measure("paillier-duration", "paillier-start", "paillier-end").duration / ROUNDS}`)
}
// https://gist.github.com/kawanet/352a2ed1d1656816b2bc
function string_to_buffer(src) {
return (new Uint16Array([].map.call(src, function(c) {
return c.charCodeAt(0)
}))).buffer;
}
function Protocol4Size() {
const regions = {
A: paillier.pubKey.encrypt(0n),
B: paillier.pubKey.encrypt(1n),
C: paillier.pubKey.encrypt(0n),
D: paillier.pubKey.encrypt(0n),
E: paillier.pubKey.encrypt(0n)
}
let ROUNDS = 10;
let size = 0;
let compressedSize = 0;
for (let x = 0; x < ROUNDS; x++) {
let s = JSON.stringify(proveRegions(regions));
size += string_to_buffer(s).byteLength;
compressedSize += LZString.compressToUint8Array(s).length;
}
return {
size: size / ROUNDS,
compressedSize: compressedSize / ROUNDS
};
}
function ZeroProofSize() {
const ROUNDS = 100;
const cipherText = paillier.pubKey.encrypt(0n)
let size = 0;
let compressedSize = 0;
for (let x = 0; x < ROUNDS; x++) {
let s = JSON.stringify(cipherText.proveNI());
size += string_to_buffer(s).byteLength;
compressedSize += LZString.compressToUint8Array(s).length;
}
return {
size: size / ROUNDS,
compressedSize: compressedSize / ROUNDS
};
2023-04-06 20:33:15 +00:00
}
</script>
2023-02-17 12:46:21 +00:00
</body>
2022-12-26 14:13:02 +00:00
</html>