Skip to content
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

Open
Finnimbrun opened this issue Oct 28, 2019 · 3 comments
Open

Unable to compress large files #2

Finnimbrun opened this issue Oct 28, 2019 · 3 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@Finnimbrun
Copy link

My file is larger than 900M and it doesn't seem to work.

@devthat devthat added the bug Something isn't working label Oct 29, 2019
@devthat
Copy link
Owner

devthat commented 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.

@devthat devthat added enhancement New feature or request help wanted Extra attention is needed and removed bug Something isn't working labels Oct 30, 2019
@auto-Dog
Copy link

auto-Dog commented 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 **

# 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)

@devthat
Copy link
Owner

devthat commented 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants