-
-
Save rndme/d25cecb8c6b41c33f98dea01b73d21f9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// public domain, from wikipedia description: https://en.wikipedia.org/wiki/RC4#Spritz | |
function rc4(key, str) { | |
var s = [], | |
j = 0, | |
x, res = [], | |
i, j, y, l = key.length, | |
m = str.length; | |
for(i = 0; i < 256; i++) s[i] = i; | |
for(i = 0; i < 256; i++) { | |
j = (j + s[i] + key.charCodeAt(i % l)) % 256; | |
x = s[i]; | |
s[i] = s[j]; | |
s[j] = x; | |
} | |
for(y = 0, i = 0, j = 0; y < m; y++) { | |
j = (j + s[i = (i + 1) % 256]) % 256; | |
x = s[i]; | |
s[i] = s[j]; | |
s[j] = x; | |
res.push(str.charCodeAt(y) ^ s[(s[i] + s[j]) % 256]); | |
} | |
return String.fromCharCode.apply(0, res); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment