python - XORing list of binary values -


i make simple function encodes string. idea follows:

  1. change string list of corresponding binary values.
  2. change chosen number corresponding binary value.
  3. xor each other.
  4. change string.

so code:

def encode (text, key): textbit=[] encoded=[] keybit=bin(key) in text:     textbit.append(bin(ord(a))) x in xrange (0, len(textbit)):     encoded.append(textbit[x])^(keybit)  return 0  word='abcdef' encode(word, 243) 

while i'm trying run it, error returned:

typeerror: unsupported operand type(s) ^: 'nonetype' , 'str'.

could tell me how fix that?

your error because of parenthesis: want add result of xor instead try xor encoded.append(...) returns.

but many other problems, have fixed of them not (you want add return , convert string too):

def encode(text, key):     textbit = []     encoded = []     in text:         textbit.append(ord(a))     x in textbit:         encoded.append(x ^ key)  word = 'abcdef' encode(word, 243) 

Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -