Ask for advice on python2.7 encryption algorithm

has a string of hundreds of kb . Now you want to encrypt this string and decrypt it to the original string by .

encryption requirements:
can compress the hundreds of kb strings into several kb or even several b
can decrypt as the original string

ask whether there are ready-made modules in thigh recommendation 2.7

Mar.10,2021

there are two built-in modules available, zlib and bz2, but they may not be able to achieve the compression ratio you require. You need to verify it. The usage is very simple, so:

import zlib
import bz2
content = "test input string"
print len(zlib.compress(content))
print len(bz2.compress(content))

if you still want to encrypt, you can use the third-party library PyCrypto,. If you don't want to use a third-party library, there seems to be no good built-in encryption algorithm. You can use XOR to do the simplest encryption and decryption by yourself. Generally speaking, the encryption algorithm will not be compressed, so you need encryption and compression algorithms together. If only unreadable plaintext is needed, compression is fine, and there is no need for encryption.

Menu