-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to compress large files #2
Comments
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 .pyx
cdef class weak_decrypt:
cdef public unsigned long key_0
cdef public unsigned long key_1
cdef public unsigned long key_2
def __cinit__(self):
self.key_0 = 305419896
self.key_1 = 591751049
self.key_2 = 878082192
def update_keys(self,int byte):
crc32 = zlib.crc32
bytes_c = bytes
cdef unsigned long factor = 134775813
self.key_0 = ~crc32(bytes_c((byte,)), ~self.key_0) & 0xFFFFFFFF
self.key_1 = (self.key_1 + (self.key_0 & 0xFF)) & 0xFFFFFFFF
self.key_1 = ((self.key_1 * factor) + 1) & 0xFFFFFFFF
# self.key_1 = ((self.key_1 * 0x8088405) + 1) & 0xFFFFFFFF
self.key_2 = ~crc32(bytes_c((self.key_1 >> 24,)), ~self.key_2) & 0xFFFFFFFF
def decrypt(self,chunk):
chunk = bytearray(chunk)
cdef int byte
cdef int i
cdef int temp
for i, byte in enumerate(chunk):
temp = self.key_2 | 2
byte ^= ((temp * (temp ^ 1)) >> 8) & 0xFF
self.update_keys(byte)
chunk[i] = byte
return bytes(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. |
My file is larger than 900M and it doesn't seem to work.
The text was updated successfully, but these errors were encountered: