我使用这个js库来处理大整数:http://www.leemon.com/crypto/BigInt.js问题是当我执行某些操作,比如mult(A,powMod(B,e,N))其中A, B,e和N是大整数我得到一个数组而不是一个大整数...然后当我想用这个结果操作时我不能像它是一个大整数那样做。我怎样才能将这个数组转换成一个大整数?
你知道一些拥有powMod和InverMod方法的javascript大整数库吗?
答案 0 :(得分:2)
数组是bigInt,它可以使用库中的可用功能进行操作。如果您希望能够以人类可读的格式查看它,请使用bigInt2str函数。
<script>
var A = randBigInt(100,1);
var B = randBigInt(100,1);
var e = randBigInt(100,1);
var N = randBigInt(100,1);
var mult, x;
console.log('A = ' + A); // A = 4145,12807,14234,10758,3424,5601,901,0
console.log('B = ' + B); // B = 8476,8451,3441,15572,3002,10012,1000,0
console.log('e = ' + e); // e = 3792,11382,3645,6320,9155,11401,789,0
console.log('N = ' + N); // N = 5401,1700,6760,6147,11285,5907,837,0
mult = mult(A, powMod(B, e, N)); // the operation works
console.log('mult = ' + mult); // mult = 24610,5611,13200,16143,988,8897,7049,13093,30523,11847,495,29557,22316,2,0
x = add(mult,N); // the operation works
console.log('x = ' + x); // x = 30011,7311,19960,22290,12273,14804,7886,13093,30523,11847,495,29557,22316,2,0
console.log('mult as string, base 10: ' + bigInt2str(mult,10)); // 291979269279106415301425615088143991732473941997421745796392
console.log('x as string, base 10: ' + bigInt2str(x,10)); // 291979269279106415301425615088815343267840898748372641292627
</script>