y dont u use the built in encryption libraries and methods
source from stackoverflowCode:def encode(key, string): encoded_chars = [] for i in xrange(string): key_c = key[i % len(key)] encoded_c = chr(ord(string[i]) + ord(encoded_c) % 256) encoded_chars.append(encoded_c) encoded_string = "".join(encoded_chars) return base64.urlsafe_b64encode(encoded_string)