#!/usr/bin/perl -w # # # # Shred.pl 0.5 by L. Wells # Secure file deletion utility # Licensed under the GPL (http://www.opensource.org/licenses/gpl-licen +se.html) # December 28, 2001 # # # # # TODO: # Finish support for other encryption algorithms. # Add annoying little progress bar type things. # # # use IO::File; use Crypt::Blowfish; use Getopt::Std; use strict; my $filename; my $verbose = 0; my %opts; getopts("vVha:f:i:", \%opts); if ($opts{f}) { $filename=$opts{f} or die "No file specified $!"; } if ($opts{v}) { do_version(); } if ($opts{h} || !$opts{f}) { do_help(); } if ($opts{V}) { $verbose = 1; } my $keysize=56; my $blocksize=8; my $random=1; my $iterations=7; my $entropyfile="/dev/urandom"; my $null=chr(0); my $one=chr(255); my $the_key = gather_entropy($keysize); my $cipher = new Crypt::Blowfish $the_key; my $b; my $i; my $size = (stat($filename))[7] or die "no $filename: $!"; sub nuke_file($); sub do_version; sub do_help; if ($opts{i}) { $iterations=$opts{i}; } for ($b=1;$b <=$iterations;$b++) { if ($verbose) { print "Wipe iteration $b\n"; } nuke_file($null); if ($verbose) { print "Null wipe $b\n"; } nuke_file($one); if ($verbose) { print "One wipe $b\n"; } nuke_file($random); if ($verbose) { print "Crypt wipe $b\n"; } } unlink ($filename); if ($verbose) { print "Wipe finished. Completed $iterations iterations\n"; } sub do_cipherstring { my $outchar = gather_entropy($blocksize); my $cipherout = $cipher->encrypt($outchar); return $cipherout; } sub gather_entropy { my $bytes=$_[0]; my $entropy_bytes; sysopen (ENTROPY, $entropyfile, O_RDONLY); sysread(ENTROPY, $entropy_bytes, $bytes); close(ENTROPY); return $entropy_bytes; } sub nuke_file ($){ my $o_w = $_[0]; sysopen(BYEBYE, $filename, O_WRONLY) or die $!; for ($i=0;$i<($size/$blocksize);$i++) { if ($o_w ne $null && $o_w ne $one) { $o_w=do_cipherstring; } my $err = syswrite(BYEBYE, $o_w, $blocksize, 0) or die $!; my $bytes += $err; } close(BYEBYE); } sub do_version { print "Shred.pl 0.5 by L. Wells\n\n"; exit(1); } sub do_help { print "Shred.pl 0.5 by L. Wells\n"; print "Usage: Shred.pl -f filename [-i iterations] [-a algorit +hm] [-vVh]\n"; print "\t-f filename\tWhere filename is the file to be nuked.\ +n"; print "\t-i iterations\tWhere iterations are the number of pas +ses for overwriting.\n"; print "\t-v\t\tPrint version information and exit.\n"; print "\t-a algorithm\tSpecify which algorithm to use for cryp +to pass. (NOT IMPLEMENTED)\n"; print "\t-V\t\tVerbose mode. Shows more detailed information ( +Default is no output).\n"; print "\t-h\t\tHelp. Prints this help information.\n\n"; exit(1); }

In reply to Shred by descartes

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.