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