Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!us.feeder.erje.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; ';-)': 0.03; '*the': 0.09; 'bytes,': 0.09; 'random': 0.14; "'rb')": 0.16; "'w')": 0.16; '-tkc': 0.16; 'compression': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'made,': 0.16; 'subject: \n ': 0.16; ':-)': 0.16; 'wrote:': 0.18; 'skip:f 30': 0.19; 'import': 0.22; 'header:In-Reply-To:1': 0.27; 'leave': 0.29; 'said,': 0.30; 'subject:that': 0.31; 'file': 0.32; 'run': 0.32; 'quite': 0.32; 'but': 0.35; 'there': 0.35; 'acceptable': 0.36; 'data,': 0.36; "didn't": 0.36; 'charset:us- ascii': 0.36; 'skip:o 20': 0.38; 'to:addr:python-list': 0.38; 'files': 0.38; 'to:addr:python.org': 0.39; 'truly': 0.60; 'talking': 0.65; 'received:50.22': 0.84 Date: Wed, 30 Oct 2013 18:01:39 -0500 From: Tim Chase To: python-list@python.org Subject: Re: Algorithm that makes maximum compression of completly diffused data. In-Reply-To: References: <205bfa4f-29de-43de-be5a-72a12d77d0c9@googlegroups.com> <0f857f7f-5947-4b3a-805d-0e9b888dfd48@googlegroups.com> X-Mailer: Claws Mail 3.8.1 (GTK+ 2.24.10; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - boston.accountservergroup.com X-AntiAbuse: Original Domain - python.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tim.thechases.com X-Get-Message-Sender-Via: boston.accountservergroup.com: authenticated_id: tim@thechases.com X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 31 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1383174008 news.xs4all.nl 15980 [2001:888:2000:d::a6]:38084 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:58140 On 2013-10-30 21:30, Joshua Landau wrote: > started talking about compressing *random data* If it's truly random bytes, as long as you don't need *the same* random data, you can compress it quite easily. Lossy compression is acceptable for images, so why not random files? :-) import os inname = "random.txt" namez = inname + '.rnz' # compress the file with open(outnamez, 'w') as f: f.write(os.stat(inname).st_size) # uncompress the file with open(namez) as f: size = int(f.read()) with open('/dev/random', 'rb') as rnd, open(inname, 'wb') as out: for i in range(size): out.write(rnd.read(1)) There are optimizations that can be made, and I didn't make it run on Win32, but I leave those as exercises for the reader. That said, this compresses *remarkably* well for large files ;-) -tkc