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
|
## Test
|
||||||
```
|
```
|
||||||
C:\Users\you\Desktop\ln>python test.py lznt1.py
|
C:\Users\you\Desktop>python test.py lznt1.py
|
||||||
[*] input size = 4067 bytes, sha1 hash = 9887522d4088152ca434a5f275adcd99c2de338d
|
[*] input size = 4034 bytes, sha1 hash = e19250d48c1e46d7d0fa46a5d345487d723559cd
|
||||||
[*] size of compressed1: 1280
|
[*] size of compressed1: 1264
|
||||||
[*] size of compressed2: 1553
|
[*] size of compressed2: 1559
|
||||||
[*] sha1 hash of compressed1: 64b9b5f92274e60d10f3ef0e517f563cc8d46bd6
|
[*] sha1 hash of compressed1: 720bd5775ee3273deaebabb29a412ea079fa79ae
|
||||||
[*] sha1 hash of compressed2: 92e737ee1d2b468800169cc7b28854b392ac8395
|
[*] sha1 hash of compressed2: 8df2fe59dba7fa4d4d01a8f12f05d7b5799238cc
|
||||||
[*] sha1 hash of decompressed11: 9887522d4088152ca434a5f275adcd99c2de338d
|
[*] sha1 hash of decompressed11: e19250d48c1e46d7d0fa46a5d345487d723559cd
|
||||||
[*] sha1 hash of decompressed12: 9887522d4088152ca434a5f275adcd99c2de338d
|
[*] sha1 hash of decompressed12: e19250d48c1e46d7d0fa46a5d345487d723559cd
|
||||||
[*] sha1 hash of decompressed21: 9887522d4088152ca434a5f275adcd99c2de338d
|
[*] sha1 hash of decompressed21: e19250d48c1e46d7d0fa46a5d345487d723559cd
|
||||||
[*] sha1 hash of decompressed22: 9887522d4088152ca434a5f275adcd99c2de338d
|
[*] sha1 hash of decompressed22: e19250d48c1e46d7d0fa46a5d345487d723559cd
|
||||||
```
|
```
|
||||||
|
|
||||||
## References
|
## References
|
||||||
|
|||||||
@@ -3,13 +3,13 @@ import sys
|
|||||||
import copy
|
import copy
|
||||||
|
|
||||||
def _decompress_chunk(chunk):
|
def _decompress_chunk(chunk):
|
||||||
out = ''
|
out = bytes()
|
||||||
while chunk:
|
while chunk:
|
||||||
flags = ord(chunk[0])
|
flags = ord(chunk[0:1])
|
||||||
chunk = chunk[1:]
|
chunk = chunk[1:]
|
||||||
for i in range(8):
|
for i in range(8):
|
||||||
if not (flags >> i & 1):
|
if not (flags >> i & 1):
|
||||||
out += chunk[0]
|
out += chunk[0:1]
|
||||||
chunk = chunk[1:]
|
chunk = chunk[1:]
|
||||||
else:
|
else:
|
||||||
flag = struct.unpack('<H', chunk[:2])[0]
|
flag = struct.unpack('<H', chunk[:2])[0]
|
||||||
@@ -25,7 +25,7 @@ def _decompress_chunk(chunk):
|
|||||||
offset = (flag >> o_shift) + 1
|
offset = (flag >> o_shift) + 1
|
||||||
|
|
||||||
if length >= offset:
|
if length >= offset:
|
||||||
tmp = out[-offset:] * (0xFFF / len(out[-offset:]) + 1)
|
tmp = out[-offset:] * int(0xFFF / len(out[-offset:]) + 1)
|
||||||
out += tmp[:length]
|
out += tmp[:length]
|
||||||
else:
|
else:
|
||||||
out += out[-offset:-offset+length]
|
out += out[-offset:-offset+length]
|
||||||
@@ -35,7 +35,7 @@ def _decompress_chunk(chunk):
|
|||||||
return out
|
return out
|
||||||
|
|
||||||
def decompress(buf, length_check=True):
|
def decompress(buf, length_check=True):
|
||||||
out = ''
|
out = bytes()
|
||||||
while buf:
|
while buf:
|
||||||
header = struct.unpack('<H', buf[:2])[0]
|
header = struct.unpack('<H', buf[:2])[0]
|
||||||
length = (header & 0xFFF) + 1
|
length = (header & 0xFFF) + 1
|
||||||
@@ -48,6 +48,7 @@ def decompress(buf, length_check=True):
|
|||||||
else:
|
else:
|
||||||
out += chunk
|
out += chunk
|
||||||
buf = buf[2+length:]
|
buf = buf[2+length:]
|
||||||
|
|
||||||
return out
|
return out
|
||||||
|
|
||||||
def _find(src, target, max_len):
|
def _find(src, target, max_len):
|
||||||
@@ -60,7 +61,7 @@ def _find(src, target, max_len):
|
|||||||
tmp_offset = len(src) - offset
|
tmp_offset = len(src) - offset
|
||||||
tmp_length = i
|
tmp_length = i
|
||||||
if tmp_offset == tmp_length:
|
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):
|
for j in range(i, max_len+1):
|
||||||
offset = tmp.rfind(target[:j])
|
offset = tmp.rfind(target[:j])
|
||||||
if offset == -1:
|
if offset == -1:
|
||||||
@@ -76,13 +77,13 @@ def _find(src, target, max_len):
|
|||||||
|
|
||||||
def _compress_chunk(chunk):
|
def _compress_chunk(chunk):
|
||||||
blob = copy.copy(chunk)
|
blob = copy.copy(chunk)
|
||||||
out = ''
|
out = bytes()
|
||||||
pow2 = 0x10
|
pow2 = 0x10
|
||||||
l_mask3 = 0x1002
|
l_mask3 = 0x1002
|
||||||
o_shift = 12
|
o_shift = 12
|
||||||
while len(blob) > 0:
|
while len(blob) > 0:
|
||||||
bits = 0
|
bits = 0
|
||||||
tmp = ''
|
tmp = bytes()
|
||||||
for i in range(8):
|
for i in range(8):
|
||||||
bits >>= 1
|
bits >>= 1
|
||||||
while pow2 < (len(chunk) - len(blob)):
|
while pow2 < (len(chunk) - len(blob)):
|
||||||
@@ -107,7 +108,7 @@ def _compress_chunk(chunk):
|
|||||||
bits |= 0x80 # set the highest bit
|
bits |= 0x80 # set the highest bit
|
||||||
blob = blob[length:]
|
blob = blob[length:]
|
||||||
else:
|
else:
|
||||||
tmp += blob[0]
|
tmp += blob[0:1]
|
||||||
blob = blob[1:]
|
blob = blob[1:]
|
||||||
if len(blob) == 0:
|
if len(blob) == 0:
|
||||||
break
|
break
|
||||||
@@ -118,7 +119,7 @@ def _compress_chunk(chunk):
|
|||||||
return out
|
return out
|
||||||
|
|
||||||
def compress(buf, chunk_size=0x1000):
|
def compress(buf, chunk_size=0x1000):
|
||||||
out = ''
|
out = bytes()
|
||||||
while buf:
|
while buf:
|
||||||
chunk = buf[:chunk_size]
|
chunk = buf[:chunk_size]
|
||||||
compressed = _compress_chunk(chunk)
|
compressed = _compress_chunk(chunk)
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ from setuptools import setup
|
|||||||
|
|
||||||
setup(
|
setup(
|
||||||
name="lznt1",
|
name="lznt1",
|
||||||
version="0.1.2",
|
version="0.2",
|
||||||
author="You Nakatsuru",
|
author="You Nakatsuru",
|
||||||
author_email="you0708@users.noreply.github.com",
|
author_email="you0708@users.noreply.github.com",
|
||||||
license="Apache License 2.0",
|
license="Apache License 2.0",
|
||||||
|
|||||||
Reference in New Issue
Block a user