I posted a question here asking if it was possible to create a PRNG in which an asymmetric private key could advance the PRNG while the public key could only reverse the PRNG. DannyNiu suggested an approach using RSA keys, for which I am working on a proof of concept here. After advancing and reversing the PRNG using this method, I expected the starting and ending states of the PRNG to be identical, but in my implementation, they are not. What am I doing wrong?
// requires BigInteger.min.js: https://github.com/peterolson/BigInteger.js/
// Using 256-bit RSA keys for fast demo only
// Keys generated using script found here: // https://en.wikipedia.org/wiki/RSA_(cryptosystem)
var rsaPrivateKey = bigInt("24776132865927824498491212731968501748100480067637351152890073639930475656193");
var rsaPublicKey = bigInt("74211765065553557319818035137797975277750578756934646327508787135523363995803");
var rsaModulus = 65537;
// Initial state for the PRNG
// Cannot be 0 or 1
var state = bigInt.randBetween(2, rsaModulus-1);
print("0: " + state.toString());
// Advance the PRNG 5x using the private key
for (var i = 1; i < 6; i++) {
state = state.modPow(rsaPrivateKey, rsaModulus);
print(i + ": " + state.toString());
}
// Reverse the PRNG 5x using the public key
for (var i = 4; i >= 0; i--) {
state = state.modPow(rsaPublicKey, rsaModulus);
print(i + ": " + state.toString());
}
function print(str){
document.body.insertAdjacentHTML("beforeend", str + "<br>\r\n");
}
Aucun commentaire:
Enregistrer un commentaire