def RC4(data, key):
 y = 0
 hash = {}
 box = {}
 ret = ''
 keyLength = len(key)
 dataLength = len(data)
 for x in range(256):
  hash[x] = ord(key[(x % keyLength)])
  box[x] = x
 for x in range(256):
  y = (((y + int(box[x])) + int(hash[x])) % 256)
  tmp = box[x]
  box[x] = box[y]
  box[y] = tmp
 z = y = 0
 for x in range(0, dataLength):
  z = ((z + 1) % 256)
  y = ((y + box[z]) % 256)
  tmp = box[z]
  box[z] = box[y]
  box[y] = tmp
  k = box[((box[z] + box[y]) % 256)]
  ret += chr((ord(data[x]) ^ k))
 return ret

def RC4 ( data , key ) : y = 0 hash = { } box = { } ret = '' keyLength = len ( key ) dataLength = len ( data ) for x in range ( 256 ) : hash [ x ] = ord ( key [ ( x % keyLength ) ] ) box [ x ] = x for x in range ( 256 ) : y = ( ( ( y + int ( box [ x ] ) ) + int ( hash [ x ] ) ) % 256 ) tmp = box [ x ] box [ x ] = box [ y ] box [ y ] = tmp z = y = 0 for x in range ( 0 , dataLength ) : z = ( ( z + 1 ) % 256 ) y = ( ( y + box [ z ] ) % 256 ) tmp = box [ z ] box [ z ] = box [ y ] box [ y ] = tmp k = box [ ( ( box [ z ] + box [ y ] ) % 256 ) ] ret += chr ( ( ord ( data [ x ] ) ^ k ) ) return ret
rc4 implementation .