diff --git a/static/js/paillier.js b/static/js/paillier.js index a1772bf..367c6da 100644 --- a/static/js/paillier.js +++ b/static/js/paillier.js @@ -1,9 +1,23 @@ let p, q, pubKey, privKey; class PubKey { - constructor(n, g) { - this.n = n; - this.g = g; + constructor(p, q) { + this.n = p * q; + this.g = this.n + 1n; + } + + encrypt(m) { + // Compute g^m r^n mod n^2 + let r = this.n; + + while (r >= n) { + r = random2048(); + } + + // Compute g^m by binomial theorem. + let gm = 1n + this.n * m; + // Compute g^m r^n from fact that g^n = 1 + return fastModularExponentiation(gm * r, this.n, this.n ** 2); } } @@ -23,6 +37,6 @@ document.addEventListener("DOMContentLoaded", () => { let n = p * q; let lambda = (p - 1n) * (q - 1n); - pubKey = new PubKey(n, n + 1n); + pubKey = new PubKey(p, q); privKey = new PrivKey(lambda, fastModularExponentiation(lambda, lambda - 1n, n)); }); diff --git a/static/js/player.js b/static/js/player.js index 0978735..74da8cb 100644 --- a/static/js/player.js +++ b/static/js/player.js @@ -69,13 +69,6 @@ class Player { this.isPlaying = true; } - /** - * Perform some game action on your turn. - * - * @param data Data received via socket. - */ - perform(data) {} - /** * End player's turn */ diff --git a/static/js/random.js b/static/js/random.js index f753bd3..38ea73f 100644 --- a/static/js/random.js +++ b/static/js/random.js @@ -4,7 +4,7 @@ class RandomSession { this.cipherTexts = {}; this.cipherKeys = {}; this.ourKey = CryptoJS.lib.WordArray.random(32).toString(); - // 32-bit as JavaScript does funny stuff at 64-bit levels. + // 32-bit as JavaScript does funny stuff at 53-bit levels. this.ourNoise = CryptoJS.lib.WordArray.random(4); this.finalValue = null; this.resolvers = [];