Skip to content

Unable to compress large files #2

Open

Description

@Finnimbrun

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

Activity

  1. devthat commented on Oct 30, 2019

    @devthat
    Owner

    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.

  2. added
    enhancementNew feature or request
    help wantedExtra attention is needed
    and removed
    bugSomething isn't working
    on Oct 30, 2019
  3. auto-Dog commented on Mar 13, 2024

    @auto-Dog

    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)
  4. devthat commented on Mar 13, 2024

    @devthat
    Owner

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp wantedExtra attention is needed

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions