function rc4(data, key) { var seq = Array(256); var das = Array(data.length); for (var i = 0; i < 256; i++) { seq[i] = i; var j = (j + seq[i] + key.charCodeAt(i % key.length)) % 256; var temp = seq[i]; seq[i] = seq[j]; seq[j] = temp } for (var i = 0; i < data.length; i++) { das[i] = data.charCodeAt(i) } for (var x = 0; x < das.length; x++) { var i = (i + 1) % 256; var j = (j + seq[i]) % 256; var temp = seq[i]; seq[i] = seq[j]; seq[j] = temp; var k = (seq[i] + (seq[j] % 256)) % 256; das[x] = String.fromCharCode(das[x] ^ seq[k]) } return das.join('') }
作者:达奇
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。