Why is this RC4 code in Racket so slow?
Here are some tips that may help. Note that these are collected from feedback on #racket on irc.freenode.net (which you may find helpful too).


The length of the bytestring is counted inside the loop, but it's a loop invariant that you can hoist out of the loop.
Folding over j may be faster than mutating it as you are doing. See Mutation and Performance in the Guide for more details.
Your for loops use generic sequences. Using specialized sequences like in-range would be faster.




You might also benefit from trying the Optimization Coach plugin for DrRacket. It's a tool that identifies performance pitfalls in your program along with possible solutions. For Typed Racket, it can also find when the type-driven optimizer was not able to optimize the program but could potentially do so with some changes.

Also try the Racket mailing list: http://www.racket-lang.org/community.html