Fix bug in random generator. Correct a proof

This commit is contained in:
2023-02-13 14:36:58 +00:00
parent bffc7a3a66
commit c4f6c24469
4 changed files with 6 additions and 7 deletions

View File

@ -3,13 +3,14 @@ let p, q, pubKey, privKey;
class PubKey {
constructor(p, q) {
this.n = p * q;
this.g = this.n + 1n;
// this.g = this.n + 1n;
}
encrypt(m) {
// Compute g^m r^n mod n^2
let r = random2048();
// Resample to avoid modulo bias.
while (r >= this.n) {
r = random2048();
}

View File

@ -21,8 +21,8 @@ function generate_bigint() {
// Drop the MSB to force into range from above
intRepr >>= 1n;
// Add 2^127 to force into range from below
intRepr += 2n ** 127n;
// Add 2^2047 to force into range from below
intRepr += 2n ** 2047n;
return intRepr;
}