Home|Personal|
Tutorials|Scripts|Stupid Tools

yaos°

 

»

Crypto.pl

 
 

#!/usr/bin/perl -w
use strict;
die("Usage: [-d] cleartext.txt encoded.txt KEY\n") if (@ARGV <= 2);

use Crypt::CBC;
use MIME::Base64;


#####################
# Encryption        #
#####################
if ($ARGV[0] ne "-d") {
my $key = $ARGV[2];
open(SRC_FILE, $ARGV[0]) || die("Can't open source-file, idiot!");
my @text = <SRC_FILE>;
close(SRC_FILE);

# Neuer Block, IDEA-Algorithmus
my $cipher = Crypt::CBC->new($key, "Crypt::IDEA");

# Ziel Datei Oeffnen
open(DEST_FILE, ">$ARGV[1]");

foreach my $i (@text) {
  # Format setzen
  $i = encode_base64($i) ;
  # Verschlüsseln und verhexen
  my $cipherhex = $cipher->encrypt_hex($i);
  print DEST_FILE "$cipherhex\n";
}
close(DEST_FILE);
print "okay\n";
}

#####################
# Decryption        #
#####################
else {
my $key = $ARGV[3];
open(SRC_FILE, $ARGV[1]) || die("Can't open source-file, idiot!");
my @text = <SRC_FILE>;
close(SRC_FILE);

# Neuer Block, IDEA-Algorithmus
my $cipher = Crypt::CBC->new($key, "Crypt::IDEA");

# Ziel Datei Oeffnen
open(DEST_FILE, ">$ARGV[2]");

foreach my $i (@text) {
  # Enthexen und entschlüsseln 
  $i = $cipher->decrypt_hex($i);
  # Formatieren
  $i = decode_base64($i);
  print DEST_FILE "$i";
}

close(DEST_FILE);
print "okay\n";
}
      

© Henrik Teichmann

 

Valid HTML 4.01! Valid CSS!