#NEWLINE# def rc4( data , key ) : #NEWLINE# #INDENT# '\n    Encrypts the data with key key using RC4. Based on the pseudocode presented in:\n\n    Using the http://en.wikipedia.org/wiki/ARC4 \n    ' #NEWLINE# S = range ( 256 ) #NEWLINE# j = 0 #NEWLINE# for i in xrange ( 256 ) : #NEWLINE# #INDENT# j = ( ( ( j + S [ i ] ) + ord ( key [ ( i % len ( key ) ) ] ) ) % 256 ) #NEWLINE# ( S [ i ] , S [ j ] ) = ( S [ j ] , S [ i ] ) #NEWLINE# #UNINDENT# i = 0 #NEWLINE# j = 0 #NEWLINE# output = [ ] #NEWLINE# for c in data : #NEWLINE# #INDENT# i = ( ( i + 1 ) % 256 ) #NEWLINE# j = ( ( j + S [ i ] ) % 256 ) #NEWLINE# ( S [ i ] , S [ j ] ) = ( S [ j ] , S [ i ] ) #NEWLINE# k = ( ord ( c ) ^ S [ ( ( S [ i ] + S [ j ] ) % 256 ) ] ) #NEWLINE# output . append ( chr ( k ) ) #NEWLINE# #UNINDENT# return '' . join ( output )