Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python efficient obfuscation of string

I need to obfuscate lines of Unicode text to slow down those who may want to extract them. Ideally this would be done with a built in Python module or a small add-on library; the string length will be the same or less than the original; and the "unobfuscation" be as fast as possible.

I have tried various character swaps and XOR routines, but they are slow. Base64 and hex encoding increase the size considerably. To date the most efficient method I've found is compressing with zlib at the lowest setting (1). Is there a better way?

like image 285
Tim Avatar asked Sep 20 '11 17:09

Tim


People also ask

Is it possible to obfuscate Python?

There is no effective way to obfuscate python such that it can not be trivially converted back to human readable. If you have code that valuable, convert it to C, or keep it on a server.

Does PyInstaller obfuscate?

PyInstaller can follow import statements that refer to Cython C object modules and bundle them. Additionally, Python bytecode can be obfuscated with AES256 by specifying an encryption key on PyInstaller's command line.

What is string obfuscation?

String obfuscation is an established technique used by proprietary, closed-source applications to protect intellectual property. Furthermore, it is also frequently used to hide spyware or malware in applications. In both cases, the techniques range from bit-manipulation over XOR operations to AES encryption.

Is PyArmor secure?

The security of each feature is different. The library with feature 21 and 25 has been protected by strong vm tool and many anti-debug technicals, it's safe. Feature 0 means no any protection, so it's better to protect it by any third tool.


1 Answers

How about the old ROT13 trick?

Python 3:

>>> import codecs
>>> x = 'some string'
>>> y = codecs.encode(x, 'rot13')
>>> y
'fbzr fgevat'
>>> codecs.decode(y, 'rot13')
u'some string'

Python 2:

>>> x = 'some string'
>>> y = x.encode('rot13')
>>> y
'fbzr fgevat'
>>> y.decode('rot13')
u'some string'

For a unicode string:

>>> x = u'國碼'
>>> print x
國碼
>>> y = x.encode('unicode-escape').encode('rot13')
>>> print y
\h570o\h78op
>>> print y.decode('rot13').decode('unicode-escape')
國碼
like image 196
jterrace Avatar answered Sep 29 '22 17:09

jterrace