From owner-freebsd-questions@FreeBSD.ORG Mon Jul 5 21:31:53 2004 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id BB50416A4CF for ; Mon, 5 Jul 2004 21:31:53 +0000 (GMT) Received: from bilbo.otenet.gr (bilbo.otenet.gr [195.170.0.13]) by mx1.FreeBSD.org (Postfix) with ESMTP id 5DA8A43D49 for ; Mon, 5 Jul 2004 21:31:51 +0000 (GMT) (envelope-from keramida@ceid.upatras.gr) Received: from gothmog.gr (patr530-a194.otenet.gr [212.205.215.194]) i65LVkrK007748 for ; Tue, 6 Jul 2004 00:31:47 +0300 Received: from gothmog.gr (gothmog [127.0.0.1]) by gothmog.gr (8.12.11/8.12.11) with ESMTP id i65LU41f026594 for ; Tue, 6 Jul 2004 00:30:04 +0300 (EEST) (envelope-from keramida@ceid.upatras.gr) Received: (from giorgos@localhost) by gothmog.gr (8.12.11/8.12.11/Submit) id i65LU4Ht026590; Tue, 6 Jul 2004 00:30:04 +0300 (EEST) (envelope-from keramida@ceid.upatras.gr) Date: Tue, 6 Jul 2004 00:30:04 +0300 From: Giorgos Keramidas To: Joe Schmoe Message-ID: <20040705213004.GC4560@gothmog.gr> References: <20040705205500.30396.qmail@web53306.mail.yahoo.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20040705205500.30396.qmail@web53306.mail.yahoo.com> cc: freebsd-questions@freebsd.org Subject: Re: making files opposite from themselves (100% change) X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 05 Jul 2004 21:31:53 -0000 On 2004-07-05 13:55, Joe Schmoe wrote: > So the question is, how do I take a given file and make it 100% > different from itself (but maintain its size and place on disk) ? > I could just output /dev/zero to it, but that would leave unchanged > all the bits that were aleady zero. Use an algorithm similar to the one shown below as a Perl script, to pick a certain percentage of the bytes within a file, and at those offsets chosen by this algorithm, use XOR with 0xFF or a random value to alter the value of only the given percentage of bytes. : #!/usr/bin/perl -w : : use strict; : my ($filesize, $percent, $k, $nparts, $partlen); : : die "usage: foo.pl FILESIZE PERCENT" : unless ($#ARGV == 1); : : $filesize = $ARGV[0]; : $percent = $ARGV[1] % 100; : : $nparts = int(($percent * $filesize) / 100); : $partlen = int($filesize / $nparts); : : srand (time ^ $$ ^ unpack "%L*", `ps axww | gzip`); : : print "offsets:"; : for ($k = 0; $k < $nparts; $k++) { : my $tmp = int(rand($partlen)); : my $nbyte = ($tmp + $k * $partlen); : print " $nbyte" : } : print "\n"; > So how do I flip the bits of an entire file ? That's even easier: : for each byte: : xor(byte, 0xFF); HTH, Giorgos