#!/usr/bin/perl

# Crypter by R3s1stanc3 (http://www.r3s1stanc3.co.cc)
# Mail: r3s1stanc3@tormail.org

use Crypt::CBC ;

if ( @ARGV[3] ) { run ( @ARGV[0], @ARGV[1], @ARGV[2], @ARGV[3] ) ; }
else { usage ( ) ; }

sub usage
{
  print "[*] Usage: $0 filename key operation algorithm\n" ;
  print "[-] Operation: dec, enc\n" ;
  print "[-] Algorithm: Twofish, Blowfish, AES\n" ;
}

sub run
{

  $file = $_[0] ;
  $key = $_[1] ;
  $op = $_[2] ;
  $alg = $_[3] ;

  if ( $op eq "dec" || $op eq "enc" ) { $op .= "rypting" ; }
  else
  {
    print "Unknown Operation\n" ;
    usage ( ) ;
    exit ;
  }

  if ( $alg eq "Twofish" || $alg eq "Blowfish" || $alg eq "AES" ) { $crypt = Crypt::CBC -> new ( -key => $key, -crypher => $alg ) ; }
  else
  {
    print "Unknown algorithm\n" ;
    usage ( ) ;
    exit ;
  }

  open ( F, "$file" ) ;
  if ( <F> =~ /ELF/ || $file =~ /\.exe$/ ) { binmode ( F ) ; }
  $crypt -> start ( $op ) ;
  while ( read ( F, $buffer, 1024 ) )
  {
    $file_new .= $crypt -> crypt ( $buffer ) ;
  }
  $file_new .= $crypt -> finish ;
  close ( F ) ;

  open ( file, ">", "$file" ) ;
  print file $file_new ;
  close (file ) ;

  print "Done\n" ;

}

