a bytxor in pythones like object is required 2c not 27str 27

Solutions on MaxInterview for a bytxor in pythones like object is required 2c not 27str 27 by the best coders in the world

showing results for - "a bytxor in pythones like object is required 2c not 27str 27"
Leonie
25 Oct 2018
1def xor_crypt_string(data, key = 'awesomepassword', encode = False, decode = False):
2   from itertools import izip, cycle
3   import base64
4   
5   if decode:
6      data = base64.decodestring(data)
7   xored = ''.join(chr(ord(x) ^ ord(y)) for (x,y) in izip(data, cycle(key)))
8   
9   if encode:
10      return base64.encodestring(xored).strip()
11   return xored
12secret_data = "XOR procedure"
13
14print("The cipher text is")
15print xor_crypt_string(secret_data, encode = True)
16print("The plain text fetched")
17print xor_crypt_string(xor_crypt_string(secret_data, encode = True), decode = True)