人民医院前端

prng4.js 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // prng4.js - uses Arcfour as a PRNG
  2. var Arcfour = /** @class */ (function () {
  3. function Arcfour() {
  4. this.i = 0;
  5. this.j = 0;
  6. this.S = [];
  7. }
  8. // Arcfour.prototype.init = ARC4init;
  9. // Initialize arcfour context from key, an array of ints, each from [0..255]
  10. Arcfour.prototype.init = function (key) {
  11. var i;
  12. var j;
  13. var t;
  14. for (i = 0; i < 256; ++i) {
  15. this.S[i] = i;
  16. }
  17. j = 0;
  18. for (i = 0; i < 256; ++i) {
  19. j = (j + this.S[i] + key[i % key.length]) & 255;
  20. t = this.S[i];
  21. this.S[i] = this.S[j];
  22. this.S[j] = t;
  23. }
  24. this.i = 0;
  25. this.j = 0;
  26. };
  27. // Arcfour.prototype.next = ARC4next;
  28. Arcfour.prototype.next = function () {
  29. var t;
  30. this.i = (this.i + 1) & 255;
  31. this.j = (this.j + this.S[this.i]) & 255;
  32. t = this.S[this.i];
  33. this.S[this.i] = this.S[this.j];
  34. this.S[this.j] = t;
  35. return this.S[(t + this.S[this.i]) & 255];
  36. };
  37. return Arcfour;
  38. }());
  39. export { Arcfour };
  40. // Plug in your RNG constructor here
  41. export function prng_newstate() {
  42. return new Arcfour();
  43. }
  44. // Pool size must be a multiple of 4 and greater than 32.
  45. // An array of bytes the size of the pool will be passed to init()
  46. export var rng_psize = 256;