Some paillier bits
This commit is contained in:
parent
235c0a0e42
commit
9f6584ba1a
@ -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));
|
||||
});
|
||||
|
@ -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
|
||||
*/
|
||||
|
@ -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 = [];
|
||||
|
Loading…
Reference in New Issue
Block a user