making files opposite from themselves (100% change)

2004-07-05 Thread Joe Schmoe
Hi,

I want to do some benchmarking and speed testing of
rsync and UFS snapshots by taking existing files,
doing rsyncs and snapshots of them and their
filesystem, and then _changing_ those files by a
certain percent difference, and rsyncing/snapshotting
again.

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.

So how do I flip the bits of an entire file ? 
Further, is there a good command line that will flip
the bits of some percentage of the file ?

thanks.



__
Do you Yahoo!?
Yahoo! Mail - 50x more storage than other providers!
http://promotions.yahoo.com/new_mail
___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: making files opposite from themselves (100% change)

2004-07-05 Thread Miguel Mendez
On Mon, 5 Jul 2004 13:55:00 -0700 (PDT)
Joe Schmoe [EMAIL PROTECTED] wrote:

Hi,

 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.
 
 So how do I flip the bits of an entire file ? 
 Further, is there a good command line that will flip
 the bits of some percentage of the file ?

The xor operation of a byte/word/dword with itself does that. You could
setup a buffer of the desired % of bytes you want to change, read the
bytes, xor them (^ in C) with itself and write back. It's trivial in
C/Perl/python/whathaveyou.

Or you could fetch some random data from /dev/urandom if you prefer.

-- 
Miguel Mendez [EMAIL PROTECTED]
http://www.energyhq.es.eu.org
PGP Key: 0xDC8514F1



pgpNScRmyLOLI.pgp
Description: PGP signature


Re: making files opposite from themselves (100% change)

2004-07-05 Thread Giorgos Keramidas
On 2004-07-05 13:55, Joe Schmoe [EMAIL PROTECTED] 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
___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: making files opposite from themselves (100% change)

2004-07-05 Thread Miguel Mendez
On Mon, 5 Jul 2004 22:59:55 +0200
Miguel Mendez [EMAIL PROTECTED] wrote:

 The xor operation of a byte/word/dword with itself does that. You
 could setup a buffer of the desired % of bytes you want to change,
 read the bytes, xor them (^ in C) with itself and write back. It's
 trivial in C/Perl/python/whathaveyou.

This, of course, is supposed to read : the bitwise not operation. Never
post before coffee.
 
Cheers,
-- 
Miguel Mendez [EMAIL PROTECTED]
http://www.energyhq.es.eu.org
PGP Key: 0xDC8514F1



pgpmBWVRdzraH.pgp
Description: PGP signature