MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / _ZipDecrypter

Function _ZipDecrypter

tools/python-3.11.9-amd64/Lib/zipfile.py:594–629  ·  view source on GitHub ↗
(pwd)

Source from the content-addressed store, hash-verified

592# plain_bytes = zd(cypher_bytes)
593
594def _ZipDecrypter(pwd):
595 key0 = 305419896
596 key1 = 591751049
597 key2 = 878082192
598
599 global _crctable
600 if _crctable is None:
601 _crctable = list(map(_gen_crc, range(256)))
602 crctable = _crctable
603
604 def crc32(ch, crc):
605 """Compute the CRC32 primitive on one byte."""
606 return (crc >> 8) ^ crctable[(crc ^ ch) & 0xFF]
607
608 def update_keys(c):
609 nonlocal key0, key1, key2
610 key0 = crc32(c, key0)
611 key1 = (key1 + (key0 & 0xFF)) & 0xFFFFFFFF
612 key1 = (key1 * 134775813 + 1) & 0xFFFFFFFF
613 key2 = crc32(key1 >> 24, key2)
614
615 for p in pwd:
616 update_keys(p)
617
618 def decrypter(data):
619 """Decrypt a bytes object."""
620 result = bytearray()
621 append = result.append
622 for c in data:
623 k = key2 | 2
624 c ^= ((k * (k^1)) >> 8) & 0xFF
625 update_keys(c)
626 append(c)
627 return bytes(result)
628
629 return decrypter
630
631
632class LZMACompressor:

Callers 1

_init_decrypterMethod · 0.85

Calls 3

listFunction · 0.85
update_keysFunction · 0.85
mapFunction · 0.50

Tested by

no test coverage detected