You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I tried this out and it eventually works with a 1gb file. The problem however is, that it takes a really long time compared to compressing without a password. I have to investigate this further.
Seems that compressor and decompressor computes slow if you only use python variable and code to compute. Similar prolem exist in python module ZipFile, where ZipCrypto algorithm are implentment in python.
I think it might work if cython or C Python API is used to accelerate compute. For example, replace the functions above, using cython. After compile the pyx file, directly use it as a module.
** But the speed just doubled with this code, so I also wonder if there's better way to accelerate **
# in weak_decrypt .pyxcdefclassweak_decrypt:
cdefpublicunsignedlongkey_0cdefpublicunsignedlongkey_1cdefpublicunsignedlongkey_2def__cinit__(self):
self.key_0=305419896self.key_1=591751049self.key_2=878082192defupdate_keys(self,intbyte):
crc32=zlib.crc32bytes_c=bytescdefunsignedlongfactor=134775813self.key_0=~crc32(bytes_c((byte,)), ~self.key_0) &0xFFFFFFFFself.key_1= (self.key_1+ (self.key_0&0xFF)) &0xFFFFFFFFself.key_1= ((self.key_1*factor) +1) &0xFFFFFFFF# self.key_1 = ((self.key_1 * 0x8088405) + 1) & 0xFFFFFFFFself.key_2=~crc32(bytes_c((self.key_1>>24,)), ~self.key_2) &0xFFFFFFFFdefdecrypt(self,chunk):
chunk=bytearray(chunk)
cdefintbytecdefinticdefinttempfori, byteinenumerate(chunk):
temp=self.key_2|2byte^= ((temp* (temp^1)) >>8) &0xFFself.update_keys(byte)
chunk[i] =bytereturnbytes(chunk)
# usage in other py file:# from weak_decrypt import weak_decrypt# dec = weak_decrypt()# out = dec.decrypt(input_byte)
Nice solution! However, this makes packaging more complicated since you would need to package binaries or do the cython compilation during installation - if that's possible.
Activity
devthat commentedon Oct 30, 2019
I tried this out and it eventually works with a 1gb file. The problem however is, that it takes a really long time compared to compressing without a password. I have to investigate this further.
auto-Dog commentedon Mar 13, 2024
Seems that compressor and decompressor computes slow if you only use python variable and code to compute. Similar prolem exist in python module ZipFile, where ZipCrypto algorithm are implentment in python.
https://github.com/devthat/zipencrypt/blob/897f03d05f5b2881e915ed346d0498f58abf3ac8/zipencrypt/zipencrypt3.py#L573C7-L573C20
I think it might work if cython or C Python API is used to accelerate compute. For example, replace the functions above, using cython. After compile the pyx file, directly use it as a module.
** But the speed just doubled with this code, so I also wonder if there's better way to accelerate **
devthat commentedon Mar 13, 2024
Nice solution! However, this makes packaging more complicated since you would need to package binaries or do the cython compilation during installation - if that's possible.