File tree 1 file changed +12
-11
lines changed 1 file changed +12
-11
lines changed Original file line number Diff line number Diff line change @@ -355,18 +355,19 @@ def process_xor_many(data, key):
355
355
else :
356
356
return bytes (a ^ b for a , b in zip (data , itertools .cycle (key )))
357
357
358
+ # formula taken from: http://stackoverflow.com/a/812039
359
+ precomputed_rotations = {amount :[(i << amount ) & 0xff | (i >> (- amount & 7 )) for i in range (256 )] for amount in range (8 )}
360
+
358
361
@staticmethod
359
362
def process_rotate_left (data , amount , group_size ):
360
363
if group_size != 1 :
361
- raise Exception (
362
- "unable to rotate group of %d bytes yet" %
363
- (group_size ,)
364
- )
365
-
366
- mask = group_size * 8 - 1
367
- anti_amount = - amount & mask
364
+ raise Exception ("unable to rotate groups other than 1 byte" )
365
+ amount = amount % 8
366
+ if amount == 0 :
367
+ return data
368
368
369
- r = bytearray (data )
370
- for i in range (len (r )):
371
- r [i ] = (r [i ] << amount ) & 0xff | (r [i ] >> anti_amount )
372
- return bytes (r )
369
+ translate = KaitaiStream .precomputed_rotations [amount ]
370
+ if PY2 :
371
+ return bytes (bytearray (translate [a ] for a in bytearray (data )))
372
+ else :
373
+ return bytes (translate [a ] for a in data )
You can’t perform that action at this time.
0 commit comments