viernes, 19 de marzo de 2010

filldisk.pl

#!/usr/bin/perl -w
#
# Usage: perl filldisk.pl > /dev/sdc

use Crypt::RC4;
use Crypt::Random qw(makerandom_octet);

my $BSIZE=4096;
my $KSIZE=16;

my $buffer;
my $rc4key=makerandom_octet(Length => $KSIZE, Strength => 1, Uniform=>1);

binmode STDOUT;

my $total=0;
my $wsize=0;

my $alarm=1;

local $SIG{ALRM} = sub { $alarm=1; };

while(1) {
if($alarm) {
print STDERR "\r$total KB";
$buffer=makerandom_octet(Length => $BSIZE, Strength => 0, Uniform=>1);
$alarm = 0;
alarm(1);
}

$buffer = RC4($rc4key, $buffer);
$wsize = syswrite(STDOUT, $buffer, $BSIZE);
last unless $wsize;
$total+=$wsize >> 10;
$rc4key=makerandom_octet(Length => $KSIZE, Strength => 0, Uniform=>1);
}

print STDERR "\n$0: $!\n$total KB written\n";
Publicar un comentario