mirror of
https://github.com/you0708/lznt1
synced 2026-06-08 18:32:11 +00:00
Python3 support
This commit is contained in:
@@ -18,16 +18,16 @@ pip install lznt1
|
||||
|
||||
## Test
|
||||
```
|
||||
C:\Users\you\Desktop\ln>python test.py lznt1.py
|
||||
[*] input size = 4067 bytes, sha1 hash = 9887522d4088152ca434a5f275adcd99c2de338d
|
||||
[*] size of compressed1: 1280
|
||||
[*] size of compressed2: 1553
|
||||
[*] sha1 hash of compressed1: 64b9b5f92274e60d10f3ef0e517f563cc8d46bd6
|
||||
[*] sha1 hash of compressed2: 92e737ee1d2b468800169cc7b28854b392ac8395
|
||||
[*] sha1 hash of decompressed11: 9887522d4088152ca434a5f275adcd99c2de338d
|
||||
[*] sha1 hash of decompressed12: 9887522d4088152ca434a5f275adcd99c2de338d
|
||||
[*] sha1 hash of decompressed21: 9887522d4088152ca434a5f275adcd99c2de338d
|
||||
[*] sha1 hash of decompressed22: 9887522d4088152ca434a5f275adcd99c2de338d
|
||||
C:\Users\you\Desktop>python test.py lznt1.py
|
||||
[*] input size = 4034 bytes, sha1 hash = e19250d48c1e46d7d0fa46a5d345487d723559cd
|
||||
[*] size of compressed1: 1264
|
||||
[*] size of compressed2: 1559
|
||||
[*] sha1 hash of compressed1: 720bd5775ee3273deaebabb29a412ea079fa79ae
|
||||
[*] sha1 hash of compressed2: 8df2fe59dba7fa4d4d01a8f12f05d7b5799238cc
|
||||
[*] sha1 hash of decompressed11: e19250d48c1e46d7d0fa46a5d345487d723559cd
|
||||
[*] sha1 hash of decompressed12: e19250d48c1e46d7d0fa46a5d345487d723559cd
|
||||
[*] sha1 hash of decompressed21: e19250d48c1e46d7d0fa46a5d345487d723559cd
|
||||
[*] sha1 hash of decompressed22: e19250d48c1e46d7d0fa46a5d345487d723559cd
|
||||
```
|
||||
|
||||
## References
|
||||
|
||||
@@ -3,13 +3,13 @@ import sys
|
||||
import copy
|
||||
|
||||
def _decompress_chunk(chunk):
|
||||
out = ''
|
||||
out = bytes()
|
||||
while chunk:
|
||||
flags = ord(chunk[0])
|
||||
flags = ord(chunk[0:1])
|
||||
chunk = chunk[1:]
|
||||
for i in range(8):
|
||||
if not (flags >> i & 1):
|
||||
out += chunk[0]
|
||||
out += chunk[0:1]
|
||||
chunk = chunk[1:]
|
||||
else:
|
||||
flag = struct.unpack('<H', chunk[:2])[0]
|
||||
@@ -25,7 +25,7 @@ def _decompress_chunk(chunk):
|
||||
offset = (flag >> o_shift) + 1
|
||||
|
||||
if length >= offset:
|
||||
tmp = out[-offset:] * (0xFFF / len(out[-offset:]) + 1)
|
||||
tmp = out[-offset:] * int(0xFFF / len(out[-offset:]) + 1)
|
||||
out += tmp[:length]
|
||||
else:
|
||||
out += out[-offset:-offset+length]
|
||||
@@ -35,7 +35,7 @@ def _decompress_chunk(chunk):
|
||||
return out
|
||||
|
||||
def decompress(buf, length_check=True):
|
||||
out = ''
|
||||
out = bytes()
|
||||
while buf:
|
||||
header = struct.unpack('<H', buf[:2])[0]
|
||||
length = (header & 0xFFF) + 1
|
||||
@@ -48,6 +48,7 @@ def decompress(buf, length_check=True):
|
||||
else:
|
||||
out += chunk
|
||||
buf = buf[2+length:]
|
||||
|
||||
return out
|
||||
|
||||
def _find(src, target, max_len):
|
||||
@@ -60,7 +61,7 @@ def _find(src, target, max_len):
|
||||
tmp_offset = len(src) - offset
|
||||
tmp_length = i
|
||||
if tmp_offset == tmp_length:
|
||||
tmp = src[offset:] * (0xFFF / len(src[offset:]) + 1)
|
||||
tmp = src[offset:] * int(0xFFF / len(src[offset:]) + 1)
|
||||
for j in range(i, max_len+1):
|
||||
offset = tmp.rfind(target[:j])
|
||||
if offset == -1:
|
||||
@@ -76,13 +77,13 @@ def _find(src, target, max_len):
|
||||
|
||||
def _compress_chunk(chunk):
|
||||
blob = copy.copy(chunk)
|
||||
out = ''
|
||||
out = bytes()
|
||||
pow2 = 0x10
|
||||
l_mask3 = 0x1002
|
||||
o_shift = 12
|
||||
while len(blob) > 0:
|
||||
bits = 0
|
||||
tmp = ''
|
||||
tmp = bytes()
|
||||
for i in range(8):
|
||||
bits >>= 1
|
||||
while pow2 < (len(chunk) - len(blob)):
|
||||
@@ -107,7 +108,7 @@ def _compress_chunk(chunk):
|
||||
bits |= 0x80 # set the highest bit
|
||||
blob = blob[length:]
|
||||
else:
|
||||
tmp += blob[0]
|
||||
tmp += blob[0:1]
|
||||
blob = blob[1:]
|
||||
if len(blob) == 0:
|
||||
break
|
||||
@@ -118,7 +119,7 @@ def _compress_chunk(chunk):
|
||||
return out
|
||||
|
||||
def compress(buf, chunk_size=0x1000):
|
||||
out = ''
|
||||
out = bytes()
|
||||
while buf:
|
||||
chunk = buf[:chunk_size]
|
||||
compressed = _compress_chunk(chunk)
|
||||
|
||||
Reference in New Issue
Block a user