Advertisement
Guest User

Untitled

a guest
Feb 7th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. # Copyright (c) 2016, multiSnow <infinity.blick.winkel@gmail.com>
  2. #
  3. # Permission to use, copy, modify, and/or distribute this software for
  4. # any purpose with or without fee is hereby granted, provided that the
  5. # above copyright notice and this permission notice appear in all
  6. # copies.
  7. #
  8. # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  9. # WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  10. # WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
  11. # AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  12. # DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  13. # PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. # TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. # PERFORMANCE OF THIS SOFTWARE.
  16.  
  17. cdef int _GenerateCRCTable(unsigned int* table):
  18. cdef unsigned int crc
  19. cdef int i,j
  20. for i in range(256):
  21. crc=i
  22. for j in range(8):
  23. if crc&1:
  24. crc=((crc>>1)&0x7FFFFFFF)^0xEDB88320
  25. else:
  26. crc=((crc>>1)&0x7FFFFFFF)
  27. table[i]=crc
  28. return 0
  29.  
  30. cdef unsigned int CRCTable[256]
  31. _GenerateCRCTable(CRCTable)
  32.  
  33. cdef unsigned int _crc32(unsigned int ch,unsigned int crc):
  34. return ((crc>>8)&0x00FFFFFF)^CRCTable[(crc^ch)&0xFF]
  35.  
  36. cdef class _ZipDecrypter:
  37.  
  38. cdef unsigned int key0,key1,key2
  39.  
  40. def __init__(self,char* pwd):
  41. self.key0=0x12345678
  42. self.key1=0x23456789
  43. self.key2=0x34567890
  44. cdef unsigned int p
  45. for p in pwd:self._UpdateKeys(p)
  46.  
  47. def __call__(self,unsigned int c):
  48. cdef unsigned int k=self.key2|2
  49. return self._UpdateKeys(c^(((k*(k^1))>>8)&0xFF))
  50.  
  51. cdef unsigned int _UpdateKeys(self,unsigned int c):
  52. self.key0=_crc32(c,self.key0)
  53. self.key1=(self.key1+(self.key0&0xFF))&0xFFFFFFFF
  54. self.key1=(self.key1*0x08088405+1)&0xFFFFFFFF
  55. self.key2=_crc32((self.key1>>24)&0xFF,self.key2)
  56. return c
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement