python - XORing list of binary values -
i make simple function encodes string. idea follows:
- change string list of corresponding binary values.
- change chosen number corresponding binary value.
- xor each other.
- 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
Post a Comment