Skip to content

Instantly share code, notes, and snippets.

@fwenzel
Forked from ttaubert/rc4.js
Last active August 29, 2015 14:08
Show Gist options
  • Save fwenzel/2b314cc7a1b864c51da1 to your computer and use it in GitHub Desktop.
Save fwenzel/2b314cc7a1b864c51da1 to your computer and use it in GitHub Desktop.
function*r(k){t=x=>(y=x%n)in s?s[y]:y;w=_=>t((s[i%n]=t(j+=f=t(i++)))+(s[j%n]=f));for(n=256,s=[i=j=0];i<n;)w(j+=k[i%k.length]);for(j=0,i=1;;)yield w()}
// A raw RC4 stream.
// Works in Firefox only (needs lots of ES6).
// 150 chars
// Usage:
for (var b of r([65,65,65])) {
console.log(b);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment