77- decodes file content to str (read)
88- encodes file content from str to bytes (write)
99"""
10- import operator
11-
1210from ..__common__ import *
1311
1412
1513__examples__ = {
1614 'enc(rotate-0|rotate-8|rotate-left-8)' : None ,
17- 'enc(rotate1|rotate-right-1|rotate_1)' : {'This is a test' : "*449\x10 49\x10 0\x10 :29:" },
18- 'dec(rotate1)' : {'*449\x10 49\x10 0\x10 :29:' : "Thhr hr ` tdrt" },
15+ 'enc(rotate1|rotate-right-1|rotate_1)' : {'This is a test' : "*4\xb4 \xb9 \x10 \xb4 \xb9 \x10 \xb0 \x10 :\xb2 \xb9 :" },
1916 'enc(rotate-left-1|rotate_left_1)' : {'This is a test' : "¨ÐÒæ@Òæ@Â@èÊæè" },
2017}
21- __guess__ = ["rotate-%s " % i for i in "12" ] + ["rotate-left-%s " % i for i in "12" ]
18+ __guess__ = ["rotate-%d " % i for i in range ( 1 , 8 ) ] + ["rotate-left-%d " % i for i in range ( 1 , 8 ) ]
2219
2320
2421if PY3 :
@@ -31,9 +28,11 @@ def _getn(i):
3128
3229
3330 def _rotaten (text , n = 1 ):
34- op = [operator .lshift , operator .rshift ][n > 0 ]
35- n = abs (n )
36- return "" .join (chr (op (ord (c ), n )) for c in ensure_str (text ))
31+ r = ""
32+ for c in ensure_str (text ):
33+ b = bin (ord (c ))[2 :].zfill (8 )
34+ r += chr (int (b [- n :] + b [:- n ], 2 ))
35+ return r
3736
3837
3938 def rotate_encode (i ):
@@ -48,5 +47,5 @@ def decode(text, errors="strict"):
4847 return decode
4948
5049
51- add ("rotate" , rotate_encode , rotate_decode , r"rotate(?:[-_]?bits)?[-_]?((?:left[-_]?)?[1-7])$" , entropy = 1. )
50+ add ("rotate" , rotate_encode , rotate_decode , r"rotate(?:[-_]?bits)?[-_]?((?:(?: left|right) [-_]?)?[1-7])$" , entropy = 1. )
5251
0 commit comments