@@ -51,28 +51,28 @@ interface IPRNG {
5151}
5252
5353export class BigInteger {
54- private static readonly DB = ( ( ) => {
54+ public static readonly DB : number = ( ( ) => {
5555 const canary = 0xDEADBEEFCAFE
5656 const j_lm = ( ( canary & 0xFFFFFF ) == 0xEFCAFE )
5757
58- if ( typeof navigator === 'undefined' )
58+ if ( typeof navigator === 'undefined' || ! navigator )
5959 return 28 // node.js
60- if ( j_lm && navigator . appName === 'Microsoft Internet Explorer' )
60+ if ( j_lm && 'appName' in navigator && navigator . appName === 'Microsoft Internet Explorer' )
6161 return 30
62- if ( j_lm && navigator . appName !== 'Netscape' )
62+ if ( j_lm && 'appName' in navigator && navigator . appName !== 'Netscape' )
6363 return 26
6464 return 28 // Mozilla/Netscape
6565 } ) ( )
6666
67- private static readonly DM = ( ( 1 << BigInteger . DB ) - 1 )
68- private static readonly DV = ( 1 << BigInteger . DB )
67+ public static readonly DM : number = ( ( 1 << BigInteger . DB ) - 1 )
68+ public static readonly DV : number = ( 1 << BigInteger . DB )
6969 private static readonly FP = 52
7070 private static readonly FV = 2 ** BigInteger . FP
7171 private static readonly F1 = BigInteger . FP - BigInteger . DB
7272 private static readonly F2 = 2 * BigInteger . DB - BigInteger . FP
7373
74- static readonly ZERO = new BigInteger ( 0 )
75- static readonly ONE = new BigInteger ( 1 )
74+ static readonly ZERO : BigInteger = new BigInteger ( 0 )
75+ static readonly ONE : BigInteger = new BigInteger ( 1 )
7676
7777 public data : number [ ] = [ ]
7878 public t : number = 0 // Array length
@@ -143,7 +143,7 @@ export class BigInteger {
143143 }
144144 else if ( randomizer ) {
145145 // New BigInteger(int, RNG)
146- const x = [ ]
146+ const x : number [ ] = new Array ( ( value >> 3 ) + 1 )
147147 const t = value & 7
148148 x . length = ( value >> 3 ) + 1
149149 randomizer . nextBytes ( x )
@@ -450,10 +450,9 @@ export class BigInteger {
450450 const r = n1 . shiftRight ( k )
451451
452452 for ( let i = 0 ; i < t ; ++ i ) {
453- // Select witness 'a' at random between 1 and n1
454453 let a : BigInteger
455454 do {
456- a = new BigInteger ( this . bitLength ( ) , this . getPrng ( ) )
455+ a = new BigInteger ( this . bitLength ( ) , new Number ( this . getPrng ( ) ) as number )
457456 } while ( a . compareTo ( BigInteger . ONE ) <= 0 || a . compareTo ( n1 ) >= 0 )
458457
459458 let y = a . modPow ( r , this )
@@ -929,8 +928,8 @@ export class BigInteger {
929928 while ( -- i >= 0 ) r . data [ i ] = 0
930929 for ( i = 0 ; i < x . t - 1 ; ++ i ) {
931930 const c = x . am ( i , x . data [ i ] , r , 2 * i , 0 , 1 )
932- if ( ( r . data [ i + x . t ] += x . am ( i + 1 , 2 * x . data [ i ] , r , 2 * i + 1 , c , x . t - i - 1 ) ) >= x . DV ) {
933- r . data [ i + x . t ] -= x . DV
931+ if ( ( r . data [ i + x . t ] += x . am ( i + 1 , 2 * x . data [ i ] , r , 2 * i + 1 , c , x . t - i - 1 ) ) >= BigInteger . DV ) {
932+ r . data [ i + x . t ] -= BigInteger . DV
934933 r . data [ i + x . t + 1 ] = 1
935934 }
936935 }
@@ -1088,7 +1087,7 @@ class Montgomery implements IReducer {
10881087 this . mp = m . invDigit ( )
10891088 this . mpl = this . mp & 0x7FFF
10901089 this . mph = this . mp >> 15
1091- this . um = ( 1 << ( m . DB - 15 ) ) - 1
1090+ this . um = ( 1 << ( BigInteger . DB - 15 ) ) - 1
10921091 this . mt2 = 2 * m . t
10931092 }
10941093
@@ -1115,11 +1114,11 @@ class Montgomery implements IReducer {
11151114 }
11161115 for ( let i = 0 ; i < this . m . t ; ++ i ) {
11171116 let j = x . data [ i ] & 0x7FFF
1118- const u0 = ( j * this . mpl + ( ( ( j * this . mph + ( x . data [ i ] >> 15 ) * this . mpl ) & this . um ) << 15 ) ) & x . DM
1117+ const u0 = ( j * this . mpl + ( ( ( j * this . mph + ( x . data [ i ] >> 15 ) * this . mpl ) & this . um ) << 15 ) ) & BigInteger . DM
11191118 j = i + this . m . t
11201119 x . data [ j ] += this . m . am ( 0 , u0 , x , i , 0 , this . m . t )
1121- while ( x . data [ j ] >= x . DV ) {
1122- x . data [ j ] -= x . DV
1120+ while ( x . data [ j ] >= BigInteger . DV ) {
1121+ x . data [ j ] -= BigInteger . DV
11231122 x . data [ ++ j ] ++
11241123 }
11251124 }
0 commit comments