title: Problems with encryption when converting Crypt:CBC example from Perl to Python (Blowfish)
body: <p>I am trying to translate the program below to Python. 
  In the end the Python code should produce the same passphrase output as the Perl variant.</p>
  
  <pre><code>#!/usr/bin/env perl
  use Crypt::CBC;
  
  my $key = 'key to the gates'; 
  my $cipher = Crypt::CBC-&gt;new(
      -key    =&gt; $key,
      -cipher =&gt; 'Blowfish',
      -salt =&gt; '12341234'  
  );
  my $pass_phrase = "secret text";
  print $cipher-&gt;encrypt_hex($pass_phrase),"\n";
  print unpack('H*', $cipher-&gt;key()), "\n";
  print unpack('H*', $cipher-&gt;iv()), "\n";
  print unpack('H*', $cipher-&gt;salt()), "\n";
  print unpack('H*', $cipher-&gt;keysize()), "\n";
  
  #output:
  #pass:53616c7465645f5f31323334313233344c0ad60f0eb9fdffc46b5cc02d76d473 &lt;- hex enc "Salted__12341234&lt;gibberish&gt;"
  #key:031f2cc96d063cf836ce42c77a8a3d25bdd959659d00a892a02b13930e92f47c82a7054256be4a0f1b3771bd36c07fe3ea4f6900f8ddebe5
  #iv:f4d50b2385a2a996
  #salt:3132333431323334
  #keysize:3536
  </code></pre>
  
  <p>Below is my python code than that decrypts successfully, but encrypts unsuccessfully.
  The successfull decryption of the perl passphrase was mostly for verify input params. (Taking IV straight from perl and removing Crypt::CBC's added 16 char of salt before decrypting made it work, various posts on SO helped me..).</p>
  
  <p>Then is the unsuccessful attempt to encryption passhphrase and generate the same output as perl.
  I think i just need to use the right combination of the verified input params to get it working...maybe the salt should be padded? Or padding in general is wrong? Or iv input should not be hexlified? (it need to be 8 chars..)</p>
  
  <p>Any input is appreciated!</p>
  
  <pre><code>!/usr/bin/env python
  from Crypto.Cipher import Blowfish
  from binascii import hexlify, unhexlify
  from struct import pack
  import base64
  
  # working decryption
  passphrase =  unhexlify("53616c7465645f5f31323334313233344c0ad60f0eb9fdffc46b5cc02d76d473"[32:])
  key = unhexlify("031f2cc96d063cf836ce42c77a8a3d25bdd959659d00a892a02b13930e92f47c82a7054256be4a0f1b3771bd36c07fe3ea4f6900f8ddebe5")
  iv  = unhexlify('f4d50b2385a2a996')
  num_padding = ord(Blowfish.new(key, Blowfish.MODE_CBC, iv).decrypt(passphrase)[-1])
  print Blowfish.new(key, Blowfish.MODE_CBC, iv).decrypt(passphrase)[:(-1*num_padding)]
  
  # --- non working encryption!
  passphrase2 = "secret text"
  key2 = 'key to the gates'
  iv2  = unhexlify('f4d50b2385a2a996')
  plength = Blowfish.block_size - len(passphrase2) % Blowfish.block_size
  padding = [plength] * plength
  pad_str = passphrase2 + pack('b' * plength, *padding)
  cipher = Blowfish.new(key2, Blowfish.MODE_CBC, iv2)
  print hexlify("Salted__12341234"+cipher.encrypt(pad_str))
  
  #output:
  #secret text
  #53616c7465645f5f31323334313233346aa3f2169677cbf282b1330b46da3114
  </code></pre>