Supercomputer and encryption and compression @ rate of 96%

Fredrik Lundh fredrik at pythonware.com
Thu Apr 14 07:49:22 EDT 2005


Will McGugan wrote:

> Please implement this as a Python module. I would like to compress my mp3 collection to single 
> bits.

here's the magic algorithm (somewhat simplified):

def algorithm(data):
    m = 102021 # magic constant
    d = [int(c) for c in str(1*2*3*4*5*m+5+4+2+1)]
    x = [ord(c) for c in hex(1+2+4+5+m*5*4*3*2*1)]
    x[d[0]*d[1]*d[2]] = x[d[-1]] + sum(d) - d[d[-d[-1]-1]] + d[0]
    x = __import__("".join(chr(c) for c in x[d[0]*d[1]:])).encodestring
    return "".join(x(data).split("\n")).rstrip("="), sum(d)-sum(reversed(d))

and here's a driver for your MP3 collection:

import glob

def compress(filename):
    data = open(filename, "rb").read()
    keycode, bit = algorithm(data)
    file = open(keycode + ".out", "wb")
    file.write(chr(bit))
    file.close()
    print "compressed", filename,
    print len(data), "=>", 1, round(100.0/len(data), 3), "%"

for file in glob.glob("*.mp3"):
    compress(file)

</F> 






More information about the Python-list mailing list