Supercomputer and encryption and compression @ rate of 96%
Will McGugan
news at NOwillmcguganSPAM.com
Thu Apr 14 11:33:08 EDT 2005
Fredrik Lundh wrote:
> 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>
>
>
Muchas gracias. Although there may be a bug. I compressed my Evanescence
albumn, but after decompression it became the complete works of Charles
Dickens..
--
http://www.willmcgugan.com
"".join( [ {'*':'@','^':'.'}.get(c,None) or chr(97+(ord(c)-84)%26) for c
in "jvyy*jvyyzpthtna^pbz" ] )
More information about the Python-list
mailing list