Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Copyright (c) 2016, multiSnow <infinity.blick.winkel@gmail.com>
- #
- # Permission to use, copy, modify, and/or distribute this software for
- # any purpose with or without fee is hereby granted, provided that the
- # above copyright notice and this permission notice appear in all
- # copies.
- #
- # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
- # WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
- # WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
- # AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
- # DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
- # PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
- # TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- # PERFORMANCE OF THIS SOFTWARE.
- cdef int _GenerateCRCTable(unsigned int* table):
- cdef unsigned int crc
- cdef int i,j
- for i in range(256):
- crc=i
- for j in range(8):
- if crc&1:
- crc=((crc>>1)&0x7FFFFFFF)^0xEDB88320
- else:
- crc=((crc>>1)&0x7FFFFFFF)
- table[i]=crc
- return 0
- cdef unsigned int CRCTable[256]
- _GenerateCRCTable(CRCTable)
- cdef unsigned int _crc32(unsigned int ch,unsigned int crc):
- return ((crc>>8)&0x00FFFFFF)^CRCTable[(crc^ch)&0xFF]
- cdef class _ZipDecrypter:
- cdef unsigned int key0,key1,key2
- def __init__(self,char* pwd):
- self.key0=0x12345678
- self.key1=0x23456789
- self.key2=0x34567890
- cdef unsigned int p
- for p in pwd:self._UpdateKeys(p)
- def __call__(self,unsigned int c):
- cdef unsigned int k=self.key2|2
- return self._UpdateKeys(c^(((k*(k^1))>>8)&0xFF))
- cdef unsigned int _UpdateKeys(self,unsigned int c):
- self.key0=_crc32(c,self.key0)
- self.key1=(self.key1+(self.key0&0xFF))&0xFFFFFFFF
- self.key1=(self.key1*0x08088405+1)&0xFFFFFFFF
- self.key2=_crc32((self.key1>>24)&0xFF,self.key2)
- return c
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement