Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Static Public Attributes | Private Member Functions
zipfile._ZipDecrypter Class Reference

List of all members.

Public Member Functions

def __init__
def __call__

Public Attributes

 key0
 key1
 key2

Static Public Attributes

tuple crctable = _GenerateCRCTable()

Private Member Functions

def _GenerateCRCTable
def _crc32
def _UpdateKeys

Detailed Description

Class to handle decryption of files stored within a ZIP archive.

ZIP supports a password-based form of encryption. Even though known
plaintext attacks have been found against it, it is still useful
to be able to get data out of such a file.

Usage:
    zd = _ZipDecrypter(mypwd)
    plain_char = zd(cypher_char)
    plain_text = map(zd, cypher_text)

Definition at line 402 of file zipfile.py.


Constructor & Destructor Documentation

def zipfile._ZipDecrypter.__init__ (   self,
  pwd 
)

Definition at line 439 of file zipfile.py.

00439 
00440     def __init__(self, pwd):
00441         self.key0 = 305419896
00442         self.key1 = 591751049
00443         self.key2 = 878082192
00444         for p in pwd:
00445             self._UpdateKeys(p)

Here is the caller graph for this function:


Member Function Documentation

def zipfile._ZipDecrypter.__call__ (   self,
  c 
)
Decrypt a single character.

Definition at line 452 of file zipfile.py.

00452 
00453     def __call__(self, c):
00454         """Decrypt a single character."""
00455         assert isinstance(c, int)
00456         k = self.key2 | 2
00457         c = c ^ (((k * (k^1)) >> 8) & 255)
00458         self._UpdateKeys(c)
00459         return c

Here is the call graph for this function:

def zipfile._ZipDecrypter._crc32 (   self,
  ch,
  crc 
) [private]
Compute the CRC32 primitive on one byte.

Definition at line 435 of file zipfile.py.

00435 
00436     def _crc32(self, ch, crc):
00437         """Compute the CRC32 primitive on one byte."""
00438         return ((crc >> 8) & 0xffffff) ^ self.crctable[(crc ^ ch) & 0xff]

Here is the caller graph for this function:

Generate a CRC-32 table.

ZIP encryption uses the CRC32 one-byte primitive for scrambling some
internal keys. We noticed that a direct implementation is faster than
relying on binascii.crc32().

Definition at line 415 of file zipfile.py.

00415 
00416     def _GenerateCRCTable():
00417         """Generate a CRC-32 table.
00418 
00419         ZIP encryption uses the CRC32 one-byte primitive for scrambling some
00420         internal keys. We noticed that a direct implementation is faster than
00421         relying on binascii.crc32().
00422         """
00423         poly = 0xedb88320
00424         table = [0] * 256
00425         for i in range(256):
00426             crc = i
00427             for j in range(8):
00428                 if crc & 1:
00429                     crc = ((crc >> 1) & 0x7FFFFFFF) ^ poly
00430                 else:
00431                     crc = ((crc >> 1) & 0x7FFFFFFF)
00432             table[i] = crc
        return table
def zipfile._ZipDecrypter._UpdateKeys (   self,
  c 
) [private]

Definition at line 446 of file zipfile.py.

00446 
00447     def _UpdateKeys(self, c):
00448         self.key0 = self._crc32(c, self.key0)
00449         self.key1 = (self.key1 + (self.key0 & 255)) & 4294967295
00450         self.key1 = (self.key1 * 134775813 + 1) & 4294967295
00451         self.key2 = self._crc32((self.key1 >> 24) & 255, self.key2)

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 433 of file zipfile.py.

Definition at line 440 of file zipfile.py.

Definition at line 441 of file zipfile.py.

Definition at line 442 of file zipfile.py.


The documentation for this class was generated from the following file: