title: How to decrypt using Blowfish algorithm in php?
body: <p>I am supposed to write a PHP script to decrypt Blowfish encrypted data. </p>
  
  <p>The data I am receiving for decryption is encrypted by another application (I have no access to it).</p>
  
  <p>The data decrypts fine when am check it using a javascript script (blowfish.js).</p>
  
  <p>How can I decrypt the data in php?</p>
  
  <p>I have tried the <code>mcrypt</code> function in PHP. The code works fine if I encrypt and decrypt using the same code. If I decrypt an encrypted code (in another app) it gives junk.</p>
  
  <p>No idea about what mode to set.</p>
  
  <p>Can anyone suggest on the code below or any PHP BlowFish code without using mcrypt?</p>
  
  <pre><code>&lt;?php
  
  class Encryption
  {
      static $cypher = 'blowfish';
      static $mode   = 'cfb';
      static $key    = '12345678';
  
      public function encrypt($plaintext)
      {
          $td = mcrypt_module_open(self::$cypher, '', self::$mode, '');
          $iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
          mcrypt_generic_init($td, self::$key, $iv);
          $crypttext = mcrypt_generic($td, $plaintext);
          mcrypt_generic_deinit($td);
          return $iv.$crypttext;
      }
  
      public function decrypt($crypttext)
      {
          $plaintext = "";
          $td        = mcrypt_module_open(self::$cypher, '', self::$mode, '');
          $ivsize    = mcrypt_enc_get_iv_size($td);
          $iv        = substr($crypttext, 0, $ivsize);
          $crypttext = substr($crypttext, $ivsize);
          if ($iv)
          {
              mcrypt_generic_init($td, self::$key, $iv);
              $plaintext = mdecrypt_generic($td, $crypttext);
          }
          return $plaintext;
      }
  }
  
  
  
  $encrypted_text = Encryption::encrypt('this text is unencrypted');
   echo "ENCRY=".$encrypted_text;echo "&lt;br/&gt;";
  
  ////I am using this part(decryption) coz data already encryption 
  // Encrypted text from app 
  $encrypted_text = '29636E7ADA7081E7F5D73121C45E20D5';
  // Decrypt text
  $decrypted_text = Encryption::decrypt($encrypted_text);
    echo "ENCRY=".$decrypted_text;echo "&lt;br/&gt;";
  
  ?&gt;
  </code></pre>