def tencode(data, key, encode=base64.b64encode, salt_length=16):
 salt = ''
 for n in range(salt_length):
  salt += chr(random.randrange(256))
 data = (salt + crypt(data, sha1((key + salt)).digest()))
 if encode:
  data = encode(data)
 return data

def tencode ( data , key , encode = base64 . b64encode , salt_length = 16 ) : salt = '' for n in range ( salt_length ) : salt += chr ( random . randrange ( 256 ) ) data = ( salt + crypt ( data , sha1 ( ( key + salt ) ) . digest ( ) ) ) if encode : data = encode ( data ) return data
rc4 encryption with random salt and final encoding .