write xor decrypt python

Solutions on MaxInterview for write xor decrypt python by the best coders in the world

showing results for - "write xor decrypt python"
Lilly
26 Sep 2020
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)