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

node.js - How to mock a third-party api calls in the backend -

node.js - Why do I get "SOCKS connection failed. Connection not allowed by ruleset" for some .onion sites? -

matlab - 0-by-1 sym - What do I need to change in order to get proper symbolic results? -