#!/usr/bin/perl
# www.cyberosis.org 
# Cyberosis InterActive.
# some home-brew crypto stuff.
# ive decided to make a version that 
# had my secure removal stuff built in.
# all i had to do pretty much was cut, and paste 8)
# remember no directorys!@
# (plastek)

use Crypt::CBC;
use Term::ReadKey;
use strict;

my $dd = '/bin/dd/';
ReadMode('normal');
my $buffer;
my $file = ($ARGV[1]);
if ($ARGV[0] eq "--encrypt") {
        encrypt_shitz();
} elsif ($ARGV[0] eq "--decrypt") {
        decrypt_shitz();
} else{
        show_help();
}


sub encrypt_shitz {
my $newfile = "$file.DES";
open (FILE, "<$file") or die "cant open $file\n";
open (NEWFILE, ">$newfile") or die "cant open $newfile\n";
ReadMode('noecho');
print "enter keyphrase\n";
my $key = ReadLine(0);
my $cipher = new Crypt::CBC("$key");
$cipher->start('encrypting');
while (read(FILE, $buffer, 1024)) {
        print NEWFILE $cipher->crypt($buffer); 
} 
print NEWFILE $cipher->finish; ReadMode('restore'); close NEWFILE; close FILE;
print "removing original file\n";
&dump_file;
}


sub decrypt_shitz {
my $newfile = "$file.NOCRYPT";
open (FILE, "<$file") or die "cant open $file\n";
open (NEWFILE, ">$newfile") or die "cant open $newfile\n";
ReadMode('noecho');
print "enter keyphrase\n";
my $key = ReadLine(0);
my $cipher = new Crypt::CBC("$key");
$cipher->start('decrypting');
while (read(FILE, $buffer, 1024)) {
        print NEWFILE $cipher->decrypt($buffer); 
} 
print NEWFILE $cipher->finish; ReadMode('restore'); close NEWFILE; close FILE;
print "removing original file\n";
&dump_file;
}


sub dump_file{
my $size = -s $file;
my $dump = "$dd if=/dev/urandom of=$file bs=$size count=1 conv=notrunc";
for (my $sloop = 1; $sloop < 10; $sloop++) {
	system('$dump');
}
unlink $file;
print "$file securely unlinked\n";
}


sub show_help {
print <<"SHOWHELP";
DEStroy 0.6 (plastek)
		CIA::Cyberosis
  --(encrypt(decrypt) (file)
SHOWHELP
exit;
}

