I can pack characters into 32 bit words (or any other fixed size), but I want to make the size in bits a parameter:
Here’s what works for 32 bits :
def vectorize_key(key):
return (v[0] << 24 | v[1] << 16 | v[2] << 8 | v[3] for v in split((ord(k) for k in key),4) )
And here’s what doesn’t work. It says int and tuple bad operands for | but I can not see how I get a tuple there. I explicitly “unpack” the tuple! :
def vectorize_key(key,word_size=32):
return (reduce(lambda p, (e,f) : p | (e << f),((x[i],i*8) for i in range(word_size/8))) for x in split((ord(k) for k in key),word_size/8))
Got it. I was missing the initilizer value for the reduce :