diff options
| author | Zaran <zaran.krleza@gmail.com> | 2012-05-06 18:51:04 -0700 |
|---|---|---|
| committer | Zaran <zaran.krleza@gmail.com> | 2012-05-06 18:51:04 -0700 |
| commit | 1a855dc54caa5ef70149718a69f7bfdc14f79469 (patch) | |
| tree | 746e241e5077d70694e53c457b4d8d1cd4ba83f7 /alias-angular/app/lib/prng4.js | |
| parent | 12bfb29d647c9750a0a773ed406f48e085099a01 (diff) | |
| download | alias-1a855dc54caa5ef70149718a69f7bfdc14f79469.tar.gz | |
More work on the registration
Diffstat (limited to 'alias-angular/app/lib/prng4.js')
| -rw-r--r-- | alias-angular/app/lib/prng4.js | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/alias-angular/app/lib/prng4.js b/alias-angular/app/lib/prng4.js new file mode 100644 index 0000000..3034f3f --- /dev/null +++ b/alias-angular/app/lib/prng4.js @@ -0,0 +1,45 @@ +// prng4.js - uses Arcfour as a PRNG + +function Arcfour() { + this.i = 0; + this.j = 0; + this.S = new Array(); +} + +// Initialize arcfour context from key, an array of ints, each from [0..255] +function ARC4init(key) { + var i, j, 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; +} + +function ARC4next() { + var 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]; +} + +Arcfour.prototype.init = ARC4init; +Arcfour.prototype.next = ARC4next; + +// Plug in your RNG constructor here +function prng_newstate() { + return new Arcfour(); +} + +// Pool size must be a multiple of 4 and greater than 32. +// An array of bytes the size of the pool will be passed to init() +var rng_psize = 256; |
