0

I tried both :

var a = new BigInteger(5);

And

var b = new BigInteger(5, 10);

But both give me the error:

TypeError: 'undefined' is not an object (evaluating 'b.nextBytes')
bnpFromNumberjsbn2.js:126

Can you only instantiate with strings?

1 Answers1

0

I'd wanted to give a better answer, but you didn't mention WHICH BigInteger library you were using.

// Yes, use the two '..'
var a = new BigInteger(5..toString());

// Of if you have a variable
var v = 10;
var a = new BigInteger(v.toString());

now, with this knowledge you can override BigInteger

(function() {
  var oldConstructor = BigInteger;
  BigInteger = function(v) {
    if (typeof v === "number") {
      return oldConstructor(""+v);
    }
    return oldConstructor(v);
  };

}());
Jeremy J Starcher
  • 23,369
  • 6
  • 54
  • 74
  • Thanks, this helps. In the title I mentioned jsbn.js but I should have added the link: http://www-cs-students.stanford.edu/~tjw/jsbn/ –  Apr 21 '14 at 13:22
  • Actually, looking at it, the new function should have two parameters -- but that is an easy enough fix. – Jeremy J Starcher Apr 21 '14 at 13:52