Skip to content

Instantly share code, notes, and snippets.

@ttaubert
Last active August 29, 2015 14:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ttaubert/4490a1b7ba14a2ed3b96 to your computer and use it in GitHub Desktop.
Save ttaubert/4490a1b7ba14a2ed3b96 to your computer and use it in GitHub Desktop.
RC4 in (almost) a tweet
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