Last active
November 26, 2019 13:57
-
-
Save jc-lab/eb1f5a31ebd4f84b2a5f00886e82a5c8 to your computer and use it in GitHub Desktop.
paillier-js recovery "r"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function fixedMod(a, b) { | |
let r = a.mod(b); | |
if(r.isNegative()) | |
r = b.plus(r); | |
return r; | |
} | |
//simplevariant | |
decrypt(c) { | |
//let phi = this._p.subtract(1).multiply(this._q.subtract(1)); | |
let P = L(bigInt(c).modPow(this.lambda, this.publicKey._n2), this.publicKey.n).multiply(this.mu).mod(this.publicKey.n); | |
let cp = fixedMod(c.multiply(bigInt(1).subtract(this._p.multiply(this.publicKey.n))), this.publicKey._n2); | |
let bn = this.publicKey.n.modInv(this.lambda); | |
let r = cp.modPow(bn, this.publicKey.n); | |
console.log("dec r = ", r.toString(16)); | |
return P; | |
} | |
//both | |
decrypt(c) { | |
let phi = this.mu.modInv(this.publicKey.n); | |
let P = L(bigInt(c).modPow(this.lambda, this.publicKey._n2), this.publicKey.n).multiply(this.mu).mod(this.publicKey.n); | |
let cp = fixedMod(c.multiply(bigInt(1).subtract(this._p.multiply(this.publicKey.n))), this.publicKey._n2); | |
let bn = this.publicKey.n.modInv(phi); | |
let r = cp.modPow(bn, this.publicKey.n); | |
console.log("dec r = ", r.toString(16)); | |
return P; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment