File tree Expand file tree Collapse file tree 1 file changed +8
-2
lines changed
Expand file tree Collapse file tree 1 file changed +8
-2
lines changed Original file line number Diff line number Diff line change 33import os
44
55EXTRA_STR = 'ENCo0D#DT{xTCh$cKe>'
6+ ENCODED_IDF = '=*=EnC0d3dH3aDer==*'
67
78
89def encode (key , clear ):
910 st = ''
10- clear += EXTRA_STR
11+ if clear .startswith (ENCODED_IDF ): # already encoded, no need to encode
12+ return clear
13+ clear += EXTRA_STR # used to check if decrypt is correct
1114 incr = get_key_hash (key )
1215 for _ in clear :
1316 st += chr (incr + ord (_ ))
14- return base64 .b64encode (st .encode ('utf-8' )).decode ('utf-8' )
17+ return ENCODED_IDF + base64 .b64encode (st .encode ('utf-8' )).decode ('utf-8' )
1518
1619
1720def decode (key , enc ):
1821 st = ''
22+ if not enc .startswith (ENCODED_IDF ): # not encoded, so not decode
23+ return enc
24+ enc = enc [len (ENCODED_IDF ):] # trim out idf
1925 enc = base64 .b64decode (enc ).decode ('utf-8' ) # dont know why urlsafe decode doesn't work
2026 incr = get_key_hash (key )
2127 for _ in enc :
You can’t perform that action at this time.
0 commit comments