0

At the moment I am working on small RSA study project. I will not post most of code here as it is trivial. Here is some data:

const p - 43;
const q - 37;
const n - 1591;
const fi(n) - 1512;
const e - 611;
const d - 683;
let secretMessage = 1111;
console.log((secretMessage ** e) % n);

In this case I get NaN. As I understand the resulting integer is too big. How can I resolve this problem? I can`t code and encode message:

const secretMessage = 21;
const codedMessage = Math.pow(secretMessage, publicExponent) % n;
console.log(`coded message - ${codedMessage}`);
const uncodedMessage = Math.pow(codedMessage, secretExponent) % n;
console.log(`uncoded message - ${uncodedMessage}`);
  • Maybe you need bignumber module https://github.com/MikeMcl/bignumber.js/ – user2258152 Sep 26 '20 at 22:09
  • The main problem for me is there any way I can calculate 1999**2001%349 in javascript? – Valery Dauzhuk Sep 26 '20 at 22:19
  • Javascript supports 53 bit integer https://stackoverflow.com/questions/38251013/how-javascript-treat-large-integers-more-than-52-bits and you could use strint library https://github.com/rauschma/strint – user2258152 Sep 26 '20 at 22:31
  • 2
    You need a [modular exponentiation](https://en.wikipedia.org/wiki/Modular_exponentiation) method. It's best if you find an existing library but it is not too hard to implement it yourself using the wikipedia article as a guide. – President James K. Polk Sep 27 '20 at 13:15

0 Answers0