]>
jfr.im git - irc/quakenet/qwebirc.git/blob - js/crypto.js
1 qwebirc
.util
.crypto
.getARC4Stream = function(key
, length
) {
5 for(var i
=0;i
<key
.length
;i
++)
6 keyint
.push(key
.charCodeAt(i
));
12 for(var i
=0;i
<256;i
++) {
13 j
= (j
+ s
[i
] + keyint
[i
% key
.length
]) & 255;
14 var w
= s
[i
]; s
[i
] = s
[j
]; s
[j
] = w
;
20 for(var k
=0;k
<length
;k
++) {
24 var w
= s
[i
]; s
[i
] = s
[j
]; s
[j
] = w
;
25 output
.push(s
[(s
[i
] + s
[j
]) & 255]);
30 qwebirc
.util
.crypto
.xorStreams = function(data
, prngstream
) {
31 if(data
.length
!= prngstream
.length
)
35 for(var i
=0;i
<data
.length
;i
++)
36 output
.push(String
.fromCharCode(data
.charCodeAt(i
) ^ prngstream
[i
]));
38 return output
.join("");
41 qwebirc
.util
.crypto
.ARC4 = function(key
, data
) {
42 var prngstream
= qwebirc
.util
.crypto
.getARC4Stream(key
, data
.length
+ 1024);
43 /* burn first 1024 bytes */
44 prngstream
= prngstream
.slice(1024);
46 return qwebirc
.util
.crypto
.xorStreams(data
, prngstream
);