export class Arcfour { constructor ( ) { this . i = 0 ; this . j = 0 ; this . S = [ ] ; } public init ( key ) { let i ; let j ; let t ; for ( i = 0 ; i < 256 ; ++ i ) { this . S [ i ] = i ; } j = 0 ; for ( i = 0 ; i < 256 ; ++ i ) { j = ( j + this . S [ i ] + key [ i % key . length ] ) & 255 ; t = this . S [ i ] ; this . S [ i ] = this . S [ j ] ; this . S [ j ] = t ; } this . i = 0 ; this . j = 0 ; } public next ( ) { let t ; this . i = ( this . i + 1 ) & 255 ; this . j = ( this . j + this . S [ this . i ] ) & 255 ; t = this . S [ this . i ] ; this . S [ this . i ] = this . S [ this . j ] ; this . S [ this . j ] = t ; return this . S [ ( t + this . S [ this . i ] ) & 255 ] ; } private i : number ; private j : number ; private S : number [ ] ; } export function prng_newstate ( ) { return new Arcfour ( ) ; } export let rng_psize = 256 ;