Date: Tue, 6 Jul 2004 00:30:04 +0300 From: Giorgos Keramidas <keramida@ceid.upatras.gr> To: Joe Schmoe <non_secure@yahoo.com> Cc: freebsd-questions@freebsd.org Subject: Re: making files opposite from themselves (100% change) Message-ID: <20040705213004.GC4560@gothmog.gr> In-Reply-To: <20040705205500.30396.qmail@web53306.mail.yahoo.com> References: <20040705205500.30396.qmail@web53306.mail.yahoo.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On 2004-07-05 13:55, Joe Schmoe <non_secure@yahoo.com> 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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20040705213004.GC4560>