Some paillier bits

This commit is contained in:
jude 2023-02-11 14:59:24 +00:00
parent 235c0a0e42
commit 9f6584ba1a
3 changed files with 19 additions and 12 deletions

View File

@ -1,9 +1,23 @@
let p, q, pubKey, privKey; let p, q, pubKey, privKey;
class PubKey { class PubKey {
constructor(n, g) { constructor(p, q) {
this.n = n; this.n = p * q;
this.g = g; 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 n = p * q;
let lambda = (p - 1n) * (q - 1n); 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)); privKey = new PrivKey(lambda, fastModularExponentiation(lambda, lambda - 1n, n));
}); });

View File

@ -69,13 +69,6 @@ class Player {
this.isPlaying = true; this.isPlaying = true;
} }
/**
* Perform some game action on your turn.
*
* @param data Data received via socket.
*/
perform(data) {}
/** /**
* End player's turn * End player's turn
*/ */

View File

@ -4,7 +4,7 @@ class RandomSession {
this.cipherTexts = {}; this.cipherTexts = {};
this.cipherKeys = {}; this.cipherKeys = {};
this.ourKey = CryptoJS.lib.WordArray.random(32).toString(); 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.ourNoise = CryptoJS.lib.WordArray.random(4);
this.finalValue = null; this.finalValue = null;
this.resolvers = []; this.resolvers = [];