コード例 #1
0
from charmap import charmap
from charmap import getNextChar
from charmap import stringToBytes
from charmap import bytesToString


def processPointer(bytes):
    length = ((bytes[0] & 0x03) << 3) + ((bytes[1] & 0xE0) >> 5) + 4
    j = ((bytes[1] & 0x1F) << 8) + bytes[2]
    return length, j - (j / 256) * 2


bytes = stringToBytes(open("WLDHELP.LZW").read()[0x80:])
lengths = {}
jumps = {}

for i in xrange(36):
    lengths[i] = 0
for i in xrange(8192):
    jumps[i] = 0
i = 0
while i < len(bytes):
    if (bytes[i] & 0xFC) == 0xF0:
        length, jump = processPointer(bytes[i:i + 3])
        lengths[length] += 1
        jumps[jump] += 1
        i += 2
    i += 1

#print lengths
#print jumps
コード例 #2
0
from charmap import charmap
from charmap import getNextChar
from charmap import stringToBytes
from charmap import bytesToString

def processPointer(bytes):
  length = ((bytes[0]&0x03) << 3) + ((bytes[1]&0xE0)>>5) + 4
  j = ((bytes[1]&0x1F)<<8) + bytes[2];
  return length, j-(j/256)*2
  
bytes=stringToBytes(open("WLDHELP.LZW").read()[0x80:])
lengths={}
jumps={}

for i in xrange(36): lengths[i]=0
for i in xrange(8192): jumps[i]=0
i = 0
while i < len(bytes):
  if (bytes[i]&0xFC)==0xF0:
    length,jump = processPointer(bytes[i:i+3])
    lengths[length] +=1
    jumps[jump] +=1
    i += 2
  i += 1
  
#print lengths
#print jumps

for i in xrange(3791,8191): 
  if jumps[i]!=0: print i
コード例 #3
0
    d = buildDict()
    m = max(d.keys())
    result = ""
    i = 0
    while i < len(bytes):
        #if i%1000 == 0: print i
        if bytes[i] == "\xfe":
            result += bytes[i]
            i += 1
            continue
        fe = bytes.find("\xfe", i, i + 35)
        if fe == -1: fe = i + 35
        size, loc = findBestSubStringInWindow(result[0 - m:], bytes[i:fe])
        if size != -1 and loc != -1:  # and not (bytes[i]=="\xfa" and bytes[i+size-1]=="\xfa"):
            a, b, c = buildPointer(d, loc, size)
            result += chr(a) + chr(b) + chr(c)
            i += size
        else:
            result += bytes[i]
            i += 1
    return result


bytes = decompress(stringToBytes(open("WLDHELP.LZW").read()[0x80:]))
s = bytesToString(bytes)
comp = compress(s, max(buildDict().keys()))
dec = decompress(stringToBytes(comp))

print dec == bytes
open("compressed.bin", "w").write(comp)
open("decompressed.bin", "w").write(bytesToString(dec))
コード例 #4
0
ファイル: compress.py プロジェクト: Wi150nZ/lioneditor
    result = ""
    i = 0
    while i < len(bytes):
        # if i%1000 == 0: print i
        if bytes[i] == "\xfe":
            result += bytes[i]
            i += 1
            continue
        fe = bytes.find("\xfe", i, i + 35)
        if fe == -1:
            fe = i + 35
        size, loc = findBestSubStringInWindow(result[0 - m :], bytes[i:fe])
        if size != -1 and loc != -1:  # and not (bytes[i]=="\xfa" and bytes[i+size-1]=="\xfa"):
            a, b, c = buildPointer(d, loc, size)
            result += chr(a) + chr(b) + chr(c)
            i += size
        else:
            result += bytes[i]
            i += 1
    return result


bytes = decompress(stringToBytes(open("WLDHELP.LZW").read()[0x80:]))
s = bytesToString(bytes)
comp = compress(s, max(buildDict().keys()))
dec = decompress(stringToBytes(comp))

print dec == bytes
open("compressed.bin", "w").write(comp)
open("decompressed.bin", "w").write(bytesToString(dec))