1

I'm looking at the Crypt::CBC lib and I misunderstand something... below an example :

#!/usr/bin/env perl
use warnings;
use strict;
use Crypt::CBC;

my $cipher = Crypt::CBC->new(
    -key    => pack("H*","0011223344556677"),
    -iv     => pack("H*","AABBCCDDEEFF0011"),
    -header => "none",
    -padding=> "null",
    -cipher => "Crypt::DES");
my $plaintext = $cipher->decrypt(pack("H*","0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF"));
print unpack("H*",$plaintext)."\n";

This script print the string :

a732b731fdcb5dbe0caa3e8b9a9f90400caa3e8b9a9f90400caa3e8b9a9f90400caa3e8b9a9f90400caa3e8b9a9f90400caa3e8b9a9f9040

It should be :

D7ED316D5F2C1F1D7C75B8D73878D2E37C75B8D73878D2E37C75B8D73878D2E37C75B8D73878D2E37C75B8D73878D2E37C75B8D73878D2E3

I use CrypTool 2.0 software and http://des.online-domain-tools.com/tool-form-submit/ to get this result.

Any ideas ?


[=> Problem Solved <=]

I have fixed the issue with -literal_key => 1, parameter.

#!/usr/bin/env perl
use warnings;
use strict;
use Crypt::CBC;

my $cipher = Crypt::CBC->new(
    -literal_key => 1,
    -key    => pack("H*","0011223344556677"),
    -iv     => pack("H*","AABBCCDDEEFF0011"),
    -header => "none",
    -padding=> "null",
    -cipher => "Crypt::DES");
my $plaintext = $cipher->decrypt(pack("H*","0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF"));
print unpack("H*",$plaintext)."\n";
Community
  • 1
  • 1
0x0ff.info
  • 11
  • 4
  • Thanks for putting in the effort to show your own solution for future readers. You could also answer your own question and accept that. That has the small advantage that your question shows as solved but it does not really make a huge difference. And welcome to SO. – DeVadder Mar 06 '14 at 15:43
  • I followed your advice ! I'll accept my answere tomorrow when SO will allow me to. ;-) – 0x0ff.info Mar 07 '14 at 09:50

1 Answers1

0

I have fixed the issue with -literal_key => 1, parameter.

#!/usr/bin/env perl
use warnings;
use strict;
use Crypt::CBC;

my $cipher = Crypt::CBC->new(
    -literal_key => 1,
    -key    => pack("H*","0011223344556677"),
    -iv     => pack("H*","AABBCCDDEEFF0011"),
    -header => "none",
    -padding=> "null",
    -cipher => "Crypt::DES");
my $plaintext = $cipher->decrypt(pack("H*","0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF"));
print unpack("H*",$plaintext)."\n";
0x0ff.info
  • 11
  • 4