Commit 6921750c authored by marcus-tun's avatar marcus-tun
Browse files

added more options and renamed key=>pass and perl_pass=>perl_key

parent e636051d
......@@ -9,25 +9,32 @@ use MIME::Base64 qw( decode_base64 );
my %opts = ();
my $verbose=0;
my $iv='0000000000000000';
my $key='0000000000000000';
my $pass='0000000000000000';
my $plaintext='hello world, today is a good day to have long strings';
my $salt='00000000'; # 0: off -- 1: on -- >1: actual salt
my $unhex=0;
# Get options
GetOptions(\%opts, 'help|h',
) or exit;
if (exists $opts{help}) {
print ("Usage: [arguments]
-v, --verbose
-i, --iv
-k, --key
-p, --plaintext\n");
-k, --pass
-t, --plaintext
-c, --ciphertext
-s, --salt
exit (0);
if (exists $opts{verbose}) {
......@@ -36,29 +43,34 @@ if (exists $opts{verbose}) {
if (exists $opts{iv}) {
$iv = trim($opts{iv});
if (exists $opts{key}) {
$key = trim($opts{key});
if (exists $opts{pass}) {
$pass = trim($opts{pass});
if (exists $opts{plaintext}) {
$plaintext = trim($opts{plaintext});
if (exists $opts{salt}) {
$salt = trim($opts{salt});
## Debug output
print ("plaintext: ".$plaintext."\n") if $verbose;
print ("iv: ".$iv."\n") if $verbose;
print ("key: ".$key."\n") if $verbose;
print ("pass: ".$pass."\n") if $verbose;
print ("salt: ".$salt."\n") if $verbose;
my $encryption_algorithm='Rijndael';
my $cipher = new Crypt::CBC ($key, $encryption_algorithm, -iv=>$iv, -header=>'none');
#my $cipher = new Crypt::CBC ($pass, $encryption_algorithm, -literal_key=>1, -iv=>$iv, -header=>'none', -salt=>$salt -keysize=>16, -blocksize=>16);
my $cipher = new Crypt::CBC ($pass, $encryption_algorithm, -iv=>$iv, -header=>'none', -salt=>$salt);
my $ciphertext= encode_base64($cipher->encrypt($plaintext));
my $perl_iv = $cipher->iv();
#my $perl_pass = unpack('H*', $cipher->key());
my $perl_pass = $cipher->key();
#print ('perl_iv: '.$perl_iv."\n") if $verbose;
#print ('perl_pass: '.$perl_pass."\n") if $verbose;
my $perl_iv = $cipher->iv();
#my $perl_key = unpack('H*', $cipher->key());
my $perl_key = $cipher->key();
print ('perl_iv: '.$perl_iv."\n") if $verbose;
......@@ -67,10 +79,11 @@ if (exists $opts{ciphertext}) {
$ciphertext = trim($opts{ciphertext});
print ("Using ciphertext from cmdline\n");
print ("ciphertext: ".$ciphertext."\n") if $verbose;
print ("ciphertext_de64: ".decode_base64($ciphertext)."\n") if $verbose;
my $de_cipher = new Crypt::CBC ($key, $encryption_algorithm, -iv=>$iv, -header=>'asdf');
my $de_cipher = new Crypt::CBC ($pass, $encryption_algorithm, -iv=>$iv, -header=>'none'-salt=>$salt);
my $new_plaintext = $de_cipher->decrypt(decode_base64($ciphertext));
print ("\n");
print ("decrypted: ".$new_plaintext."\n") if $verbose;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment