Вход Регистрация
Файл: oc-includes/phpseclib/Crypt/DES.php
Строк: 572
<?php

/**
 * Pure-PHP implementation of DES.
 *
 * Uses mcrypt, if available, and an internal implementation, otherwise.
 *
 * PHP versions 4 and 5
 *
 * Useful resources are as follows:
 *
 *  - {@link http://en.wikipedia.org/wiki/DES_supplementary_material Wikipedia: DES supplementary material}
 *  - {@link http://www.itl.nist.gov/fipspubs/fip46-2.htm FIPS 46-2 - (DES), Data Encryption Standard}
 *  - {@link http://www.cs.eku.edu/faculty/styer/460/Encrypt/JS-DES.html JavaScript DES Example}
 *
 * Here's a short example of how to use this library:
 * <code>
 * <?php
 *    include 'Crypt/DES.php';
 *
 *    $des = new Crypt_DES();
 *
 *    $des->setKey('abcdefgh');
 *
 *    $size = 10 * 1024;
 *    $plaintext = '';
 *    for ($i = 0; $i < $size; $i++) {
 *        $plaintext.= 'a';
 *    }
 *
 *    echo $des->decrypt($des->encrypt($plaintext));
 * ?>
 * </code>
 *
 * LICENSE: Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 *
 * @category  Crypt
 * @package   Crypt_DES
 * @author    Jim Wigginton <terrafrost@php.net>
 * @copyright 2007 Jim Wigginton
 * @license   http://www.opensource.org/licenses/mit-license.html  MIT License
 * @link      http://phpseclib.sourceforge.net
 */

/**
 * Include Crypt_Base
 *
 * Base cipher class
 */
if (!class_exists('Crypt_Base')) {
    include_once 
'Base.php';
}

/**#@+
 * @access private
 * @see Crypt_DES::_setupKey()
 * @see Crypt_DES::_processBlock()
 */
/**
 * Contains $keys[CRYPT_DES_ENCRYPT]
 */
define('CRYPT_DES_ENCRYPT'0);
/**
 * Contains $keys[CRYPT_DES_DECRYPT]
 */
define('CRYPT_DES_DECRYPT'1);
/**#@-*/

/**#@+
 * @access public
 * @see Crypt_DES::encrypt()
 * @see Crypt_DES::decrypt()
 */
/**
 * Encrypt / decrypt using the Counter mode.
 *
 * Set to -1 since that's what Crypt/Random.php uses to index the CTR mode.
 *
 * @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Counter_.28CTR.29
 */
define('CRYPT_DES_MODE_CTR'CRYPT_MODE_CTR);
/**
 * Encrypt / decrypt using the Electronic Code Book mode.
 *
 * @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Electronic_codebook_.28ECB.29
 */
define('CRYPT_DES_MODE_ECB'CRYPT_MODE_ECB);
/**
 * Encrypt / decrypt using the Code Book Chaining mode.
 *
 * @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Cipher-block_chaining_.28CBC.29
 */
define('CRYPT_DES_MODE_CBC'CRYPT_MODE_CBC);
/**
 * Encrypt / decrypt using the Cipher Feedback mode.
 *
 * @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Cipher_feedback_.28CFB.29
 */
define('CRYPT_DES_MODE_CFB'CRYPT_MODE_CFB);
/**
 * Encrypt / decrypt using the Cipher Feedback mode.
 *
 * @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Output_feedback_.28OFB.29
 */
define('CRYPT_DES_MODE_OFB'CRYPT_MODE_OFB);
/**#@-*/

/**
 * Pure-PHP implementation of DES.
 *
 * @package Crypt_DES
 * @author  Jim Wigginton <terrafrost@php.net>
 * @access  public
 */
class Crypt_DES extends Crypt_Base
{
    
/**
     * Block Length of the cipher
     *
     * @see Crypt_Base::block_size
     * @var Integer
     * @access private
     */
    
var $block_size 8;

    
/**
     * The Key
     *
     * @see Crypt_Base::key
     * @see setKey()
     * @var String
     * @access private
     */
    
var $key "";

    
/**
     * The default password key_size used by setPassword()
     *
     * @see Crypt_Base::password_key_size
     * @see Crypt_Base::setPassword()
     * @var Integer
     * @access private
     */
    
var $password_key_size 8;

    
/**
     * The namespace used by the cipher for its constants.
     *
     * @see Crypt_Base::const_namespace
     * @var String
     * @access private
     */
    
var $const_namespace 'DES';

    
/**
     * The mcrypt specific name of the cipher
     *
     * @see Crypt_Base::cipher_name_mcrypt
     * @var String
     * @access private
     */
    
var $cipher_name_mcrypt 'des';

    
/**
     * The OpenSSL names of the cipher / modes
     *
     * @see Crypt_Base::openssl_mode_names
     * @var Array
     * @access private
     */
    
var $openssl_mode_names = array(
        
CRYPT_MODE_ECB => 'des-ecb',
        
CRYPT_MODE_CBC => 'des-cbc',
        
CRYPT_MODE_CFB => 'des-cfb',
        
CRYPT_MODE_OFB => 'des-ofb'
        
// CRYPT_MODE_CTR is undefined for DES
    
);

    
/**
     * Optimizing value while CFB-encrypting
     *
     * @see Crypt_Base::cfb_init_len
     * @var Integer
     * @access private
     */
    
var $cfb_init_len 500;

    
/**
     * Switch for DES/3DES encryption
     *
     * Used only if $engine == CRYPT_DES_MODE_INTERNAL
     *
     * @see Crypt_DES::_setupKey()
     * @see Crypt_DES::_processBlock()
     * @var Integer
     * @access private
     */
    
var $des_rounds 1;

    
/**
     * max possible size of $key
     *
     * @see Crypt_DES::setKey()
     * @var String
     * @access private
     */
    
var $key_size_max 8;

    
/**
     * The Key Schedule
     *
     * @see Crypt_DES::_setupKey()
     * @var Array
     * @access private
     */
    
var $keys;

    
/**
     * Shuffle table.
     *
     * For each byte value index, the entry holds an 8-byte string
     * with each byte containing all bits in the same state as the
     * corresponding bit in the index value.
     *
     * @see Crypt_DES::_processBlock()
     * @see Crypt_DES::_setupKey()
     * @var Array
     * @access private
     */
    
var $shuffle = array(
        
"x00x00x00x00x00x00x00x00""x00x00x00x00x00x00x00xFF",
        
"x00x00x00x00x00x00xFFx00""x00x00x00x00x00x00xFFxFF",
        
"x00x00x00x00x00xFFx00x00""x00x00x00x00x00xFFx00xFF",
        
"x00x00x00x00x00xFFxFFx00""x00x00x00x00x00xFFxFFxFF",
        
"x00x00x00x00xFFx00x00x00""x00x00x00x00xFFx00x00xFF",
        
"x00x00x00x00xFFx00xFFx00""x00x00x00x00xFFx00xFFxFF",
        
"x00x00x00x00xFFxFFx00x00""x00x00x00x00xFFxFFx00xFF",
        
"x00x00x00x00xFFxFFxFFx00""x00x00x00x00xFFxFFxFFxFF",
        
"x00x00x00xFFx00x00x00x00""x00x00x00xFFx00x00x00xFF",
        
"x00x00x00xFFx00x00xFFx00""x00x00x00xFFx00x00xFFxFF",
        
"x00x00x00xFFx00xFFx00x00""x00x00x00xFFx00xFFx00xFF",
        
"x00x00x00xFFx00xFFxFFx00""x00x00x00xFFx00xFFxFFxFF",
        
"x00x00x00xFFxFFx00x00x00""x00x00x00xFFxFFx00x00xFF",
        
"x00x00x00xFFxFFx00xFFx00""x00x00x00xFFxFFx00xFFxFF",
        
"x00x00x00xFFxFFxFFx00x00""x00x00x00xFFxFFxFFx00xFF",
        
"x00x00x00xFFxFFxFFxFFx00""x00x00x00xFFxFFxFFxFFxFF",
        
"x00x00xFFx00x00x00x00x00""x00x00xFFx00x00x00x00xFF",
        
"x00x00xFFx00x00x00xFFx00""x00x00xFFx00x00x00xFFxFF",
        
"x00x00xFFx00x00xFFx00x00""x00x00xFFx00x00xFFx00xFF",
        
"x00x00xFFx00x00xFFxFFx00""x00x00xFFx00x00xFFxFFxFF",
        
"x00x00xFFx00xFFx00x00x00""x00x00xFFx00xFFx00x00xFF",
        
"x00x00xFFx00xFFx00xFFx00""x00x00xFFx00xFFx00xFFxFF",
        
"x00x00xFFx00xFFxFFx00x00""x00x00xFFx00xFFxFFx00xFF",
        
"x00x00xFFx00xFFxFFxFFx00""x00x00xFFx00xFFxFFxFFxFF",
        
"x00x00xFFxFFx00x00x00x00""x00x00xFFxFFx00x00x00xFF",
        
"x00x00xFFxFFx00x00xFFx00""x00x00xFFxFFx00x00xFFxFF",
        
"x00x00xFFxFFx00xFFx00x00""x00x00xFFxFFx00xFFx00xFF",
        
"x00x00xFFxFFx00xFFxFFx00""x00x00xFFxFFx00xFFxFFxFF",
        
"x00x00xFFxFFxFFx00x00x00""x00x00xFFxFFxFFx00x00xFF",
        
"x00x00xFFxFFxFFx00xFFx00""x00x00xFFxFFxFFx00xFFxFF",
        
"x00x00xFFxFFxFFxFFx00x00""x00x00xFFxFFxFFxFFx00xFF",
        
"x00x00xFFxFFxFFxFFxFFx00""x00x00xFFxFFxFFxFFxFFxFF",
        
"x00xFFx00x00x00x00x00x00""x00xFFx00x00x00x00x00xFF",
        
"x00xFFx00x00x00x00xFFx00""x00xFFx00x00x00x00xFFxFF",
        
"x00xFFx00x00x00xFFx00x00""x00xFFx00x00x00xFFx00xFF",
        
"x00xFFx00x00x00xFFxFFx00""x00xFFx00x00x00xFFxFFxFF",
        
"x00xFFx00x00xFFx00x00x00""x00xFFx00x00xFFx00x00xFF",
        
"x00xFFx00x00xFFx00xFFx00""x00xFFx00x00xFFx00xFFxFF",
        
"x00xFFx00x00xFFxFFx00x00""x00xFFx00x00xFFxFFx00xFF",
        
"x00xFFx00x00xFFxFFxFFx00""x00xFFx00x00xFFxFFxFFxFF",
        
"x00xFFx00xFFx00x00x00x00""x00xFFx00xFFx00x00x00xFF",
        
"x00xFFx00xFFx00x00xFFx00""x00xFFx00xFFx00x00xFFxFF",
        
"x00xFFx00xFFx00xFFx00x00""x00xFFx00xFFx00xFFx00xFF",
        
"x00xFFx00xFFx00xFFxFFx00""x00xFFx00xFFx00xFFxFFxFF",
        
"x00xFFx00xFFxFFx00x00x00""x00xFFx00xFFxFFx00x00xFF",
        
"x00xFFx00xFFxFFx00xFFx00""x00xFFx00xFFxFFx00xFFxFF",
        
"x00xFFx00xFFxFFxFFx00x00""x00xFFx00xFFxFFxFFx00xFF",
        
"x00xFFx00xFFxFFxFFxFFx00""x00xFFx00xFFxFFxFFxFFxFF",
        
"x00xFFxFFx00x00x00x00x00""x00xFFxFFx00x00x00x00xFF",
        
"x00xFFxFFx00x00x00xFFx00""x00xFFxFFx00x00x00xFFxFF",
        
"x00xFFxFFx00x00xFFx00x00""x00xFFxFFx00x00xFFx00xFF",
        
"x00xFFxFFx00x00xFFxFFx00""x00xFFxFFx00x00xFFxFFxFF",
        
"x00xFFxFFx00xFFx00x00x00""x00xFFxFFx00xFFx00x00xFF",
        
"x00xFFxFFx00xFFx00xFFx00""x00xFFxFFx00xFFx00xFFxFF",
        
"x00xFFxFFx00xFFxFFx00x00""x00xFFxFFx00xFFxFFx00xFF",
        
"x00xFFxFFx00xFFxFFxFFx00""x00xFFxFFx00xFFxFFxFFxFF",
        
"x00xFFxFFxFFx00x00x00x00""x00xFFxFFxFFx00x00x00xFF",
        
"x00xFFxFFxFFx00x00xFFx00""x00xFFxFFxFFx00x00xFFxFF",
        
"x00xFFxFFxFFx00xFFx00x00""x00xFFxFFxFFx00xFFx00xFF",
        
"x00xFFxFFxFFx00xFFxFFx00""x00xFFxFFxFFx00xFFxFFxFF",
        
"x00xFFxFFxFFxFFx00x00x00""x00xFFxFFxFFxFFx00x00xFF",
        
"x00xFFxFFxFFxFFx00xFFx00""x00xFFxFFxFFxFFx00xFFxFF",
        
"x00xFFxFFxFFxFFxFFx00x00""x00xFFxFFxFFxFFxFFx00xFF",
        
"x00xFFxFFxFFxFFxFFxFFx00""x00xFFxFFxFFxFFxFFxFFxFF",
        
"xFFx00x00x00x00x00x00x00""xFFx00x00x00x00x00x00xFF",
        
"xFFx00x00x00x00x00xFFx00""xFFx00x00x00x00x00xFFxFF",
        
"xFFx00x00x00x00xFFx00x00""xFFx00x00x00x00xFFx00xFF",
        
"xFFx00x00x00x00xFFxFFx00""xFFx00x00x00x00xFFxFFxFF",
        
"xFFx00x00x00xFFx00x00x00""xFFx00x00x00xFFx00x00xFF",
        
"xFFx00x00x00xFFx00xFFx00""xFFx00x00x00xFFx00xFFxFF",
        
"xFFx00x00x00xFFxFFx00x00""xFFx00x00x00xFFxFFx00xFF",
        
"xFFx00x00x00xFFxFFxFFx00""xFFx00x00x00xFFxFFxFFxFF",
        
"xFFx00x00xFFx00x00x00x00""xFFx00x00xFFx00x00x00xFF",
        
"xFFx00x00xFFx00x00xFFx00""xFFx00x00xFFx00x00xFFxFF",
        
"xFFx00x00xFFx00xFFx00x00""xFFx00x00xFFx00xFFx00xFF",
        
"xFFx00x00xFFx00xFFxFFx00""xFFx00x00xFFx00xFFxFFxFF",
        
"xFFx00x00xFFxFFx00x00x00""xFFx00x00xFFxFFx00x00xFF",
        
"xFFx00x00xFFxFFx00xFFx00""xFFx00x00xFFxFFx00xFFxFF",
        
"xFFx00x00xFFxFFxFFx00x00""xFFx00x00xFFxFFxFFx00xFF",
        
"xFFx00x00xFFxFFxFFxFFx00""xFFx00x00xFFxFFxFFxFFxFF",
        
"xFFx00xFFx00x00x00x00x00""xFFx00xFFx00x00x00x00xFF",
        
"xFFx00xFFx00x00x00xFFx00""xFFx00xFFx00x00x00xFFxFF",
        
"xFFx00xFFx00x00xFFx00x00""xFFx00xFFx00x00xFFx00xFF",
        
"xFFx00xFFx00x00xFFxFFx00""xFFx00xFFx00x00xFFxFFxFF",
        
"xFFx00xFFx00xFFx00x00x00""xFFx00xFFx00xFFx00x00xFF",
        
"xFFx00xFFx00xFFx00xFFx00""xFFx00xFFx00xFFx00xFFxFF",
        
"xFFx00xFFx00xFFxFFx00x00""xFFx00xFFx00xFFxFFx00xFF",
        
"xFFx00xFFx00xFFxFFxFFx00""xFFx00xFFx00xFFxFFxFFxFF",
        
"xFFx00xFFxFFx00x00x00x00""xFFx00xFFxFFx00x00x00xFF",
        
"xFFx00xFFxFFx00x00xFFx00""xFFx00xFFxFFx00x00xFFxFF",
        
"xFFx00xFFxFFx00xFFx00x00""xFFx00xFFxFFx00xFFx00xFF",
        
"xFFx00xFFxFFx00xFFxFFx00""xFFx00xFFxFFx00xFFxFFxFF",
        
"xFFx00xFFxFFxFFx00x00x00""xFFx00xFFxFFxFFx00x00xFF",
        
"xFFx00xFFxFFxFFx00xFFx00""xFFx00xFFxFFxFFx00xFFxFF",
        
"xFFx00xFFxFFxFFxFFx00x00""xFFx00xFFxFFxFFxFFx00xFF",
        
"xFFx00xFFxFFxFFxFFxFFx00""xFFx00xFFxFFxFFxFFxFFxFF",
        
"xFFxFFx00x00x00x00x00x00""xFFxFFx00x00x00x00x00xFF",
        
"xFFxFFx00x00x00x00xFFx00""xFFxFFx00x00x00x00xFFxFF",
        
"xFFxFFx00x00x00xFFx00x00""xFFxFFx00x00x00xFFx00xFF",
        
"xFFxFFx00x00x00xFFxFFx00""xFFxFFx00x00x00xFFxFFxFF",
        
"xFFxFFx00x00xFFx00x00x00""xFFxFFx00x00xFFx00x00xFF",
        
"xFFxFFx00x00xFFx00xFFx00""xFFxFFx00x00xFFx00xFFxFF",
        
"xFFxFFx00x00xFFxFFx00x00""xFFxFFx00x00xFFxFFx00xFF",
        
"xFFxFFx00x00xFFxFFxFFx00""xFFxFFx00x00xFFxFFxFFxFF",
        
"xFFxFFx00xFFx00x00x00x00""xFFxFFx00xFFx00x00x00xFF",
        
"xFFxFFx00xFFx00x00xFFx00""xFFxFFx00xFFx00x00xFFxFF",
        
"xFFxFFx00xFFx00xFFx00x00""xFFxFFx00xFFx00xFFx00xFF",
        
"xFFxFFx00xFFx00xFFxFFx00""xFFxFFx00xFFx00xFFxFFxFF",
        
"xFFxFFx00xFFxFFx00x00x00""xFFxFFx00xFFxFFx00x00xFF",
        
"xFFxFFx00xFFxFFx00xFFx00""xFFxFFx00xFFxFFx00xFFxFF",
        
"xFFxFFx00xFFxFFxFFx00x00""xFFxFFx00xFFxFFxFFx00xFF",
        
"xFFxFFx00xFFxFFxFFxFFx00""xFFxFFx00xFFxFFxFFxFFxFF",
        
"xFFxFFxFFx00x00x00x00x00""xFFxFFxFFx00x00x00x00xFF",
        
"xFFxFFxFFx00x00x00xFFx00""xFFxFFxFFx00x00x00xFFxFF",
        
"xFFxFFxFFx00x00xFFx00x00""xFFxFFxFFx00x00xFFx00xFF",
        
"xFFxFFxFFx00x00xFFxFFx00""xFFxFFxFFx00x00xFFxFFxFF",
        
"xFFxFFxFFx00xFFx00x00x00""xFFxFFxFFx00xFFx00x00xFF",
        
"xFFxFFxFFx00xFFx00xFFx00""xFFxFFxFFx00xFFx00xFFxFF",
        
"xFFxFFxFFx00xFFxFFx00x00""xFFxFFxFFx00xFFxFFx00xFF",
        
"xFFxFFxFFx00xFFxFFxFFx00""xFFxFFxFFx00xFFxFFxFFxFF",
        
"xFFxFFxFFxFFx00x00x00x00""xFFxFFxFFxFFx00x00x00xFF",
        
"xFFxFFxFFxFFx00x00xFFx00""xFFxFFxFFxFFx00x00xFFxFF",
        
"xFFxFFxFFxFFx00xFFx00x00""xFFxFFxFFxFFx00xFFx00xFF",
        
"xFFxFFxFFxFFx00xFFxFFx00""xFFxFFxFFxFFx00xFFxFFxFF",
        
"xFFxFFxFFxFFxFFx00x00x00""xFFxFFxFFxFFxFFx00x00xFF",
        
"xFFxFFxFFxFFxFFx00xFFx00""xFFxFFxFFxFFxFFx00xFFxFF",
        
"xFFxFFxFFxFFxFFxFFx00x00""xFFxFFxFFxFFxFFxFFx00xFF",
        
"xFFxFFxFFxFFxFFxFFxFFx00""xFFxFFxFFxFFxFFxFFxFFxFF"
    
);

    
/**
     * IP mapping helper table.
     *
     * Indexing this table with each source byte performs the initial bit permutation.
     *
     * @var Array
     * @access private
     */
    
var $ipmap = array(
        
0x000x100x010x110x200x300x210x31,
        
0x020x120x030x130x220x320x230x33,
        
0x400x500x410x510x600x700x610x71,
        
0x420x520x430x530x620x720x630x73,
        
0x040x140x050x150x240x340x250x35,
        
0x060x160x070x170x260x360x270x37,
        
0x440x540x450x550x640x740x650x75,
        
0x460x560x470x570x660x760x670x77,
        
0x800x900x810x910xA00xB00xA10xB1,
        
0x820x920x830x930xA20xB20xA30xB3,
        
0xC00xD00xC10xD10xE00xF00xE10xF1,
        
0xC20xD20xC30xD30xE20xF20xE30xF3,
        
0x840x940x850x950xA40xB40xA50xB5,
        
0x860x960x870x970xA60xB60xA70xB7,
        
0xC40xD40xC50xD50xE40xF40xE50xF5,
        
0xC60xD60xC70xD70xE60xF60xE70xF7,
        
0x080x180x090x190x280x380x290x39,
        
0x0A0x1A0x0B0x1B0x2A0x3A0x2B0x3B,
        
0x480x580x490x590x680x780x690x79,
        
0x4A0x5A0x4B0x5B0x6A0x7A0x6B0x7B,
        
0x0C0x1C0x0D0x1D0x2C0x3C0x2D0x3D,
        
0x0E0x1E0x0F0x1F0x2E0x3E0x2F0x3F,
        
0x4C0x5C0x4D0x5D0x6C0x7C0x6D0x7D,
        
0x4E0x5E0x4F0x5F0x6E0x7E0x6F0x7F,
        
0x880x980x890x990xA80xB80xA90xB9,
        
0x8A0x9A0x8B0x9B0xAA0xBA0xAB0xBB,
        
0xC80xD80xC90xD90xE80xF80xE90xF9,
        
0xCA0xDA0xCB0xDB0xEA0xFA0xEB0xFB,
        
0x8C0x9C0x8D0x9D0xAC0xBC0xAD0xBD,
        
0x8E0x9E0x8F0x9F0xAE0xBE0xAF0xBF,
        
0xCC0xDC0xCD0xDD0xEC0xFC0xED0xFD,
        
0xCE0xDE0xCF0xDF0xEE0xFE0xEF0xFF
    
);

    
/**
     * Inverse IP mapping helper table.
     * Indexing this table with a byte value reverses the bit order.
     *
     * @var Array
     * @access private
     */
    
var $invipmap = array(
        
0x000x800x400xC00x200xA00x600xE0,
        
0x100x900x500xD00x300xB00x700xF0,
        
0x080x880x480xC80x280xA80x680xE8,
        
0x180x980x580xD80x380xB80x780xF8,
        
0x040x840x440xC40x240xA40x640xE4,
        
0x140x940x540xD40x340xB40x740xF4,
        
0x0C0x8C0x4C0xCC0x2C0xAC0x6C0xEC,
        
0x1C0x9C0x5C0xDC0x3C0xBC0x7C0xFC,
        
0x020x820x420xC20x220xA20x620xE2,
        
0x120x920x520xD20x320xB20x720xF2,
        
0x0A0x8A0x4A0xCA0x2A0xAA0x6A0xEA,
        
0x1A0x9A0x5A0xDA0x3A0xBA0x7A0xFA,
        
0x060x860x460xC60x260xA60x660xE6,
        
0x160x960x560xD60x360xB60x760xF6,
        
0x0E0x8E0x4E0xCE0x2E0xAE0x6E0xEE,
        
0x1E0x9E0x5E0xDE0x3E0xBE0x7E0xFE,
        
0x010x810x410xC10x210xA10x610xE1,
        
0x110x910x510xD10x310xB10x710xF1,
        
0x090x890x490xC90x290xA90x690xE9,
        
0x190x990x590xD90x390xB90x790xF9,
        
0x050x850x450xC50x250xA50x650xE5,
        
0x150x950x550xD50x350xB50x750xF5,
        
0x0D0x8D0x4D0xCD0x2D0xAD0x6D0xED,
        
0x1D0x9D0x5D0xDD0x3D0xBD0x7D0xFD,
        
0x030x830x430xC30x230xA30x630xE3,
        
0x130x930x530xD30x330xB30x730xF3,
        
0x0B0x8B0x4B0xCB0x2B0xAB0x6B0xEB,
        
0x1B0x9B0x5B0xDB0x3B0xBB0x7B0xFB,
        
0x070x870x470xC70x270xA70x670xE7,
        
0x170x970x570xD70x370xB70x770xF7,
        
0x0F0x8F0x4F0xCF0x2F0xAF0x6F0xEF,
        
0x1F0x9F0x5F0xDF0x3F0xBF0x7F0xFF
    
);

    
/**
     * Pre-permuted S-box1
     *
     * Each box ($sbox1-$sbox8) has been vectorized, then each value pre-permuted using the
     * P table: concatenation can then be replaced by exclusive ORs.
     *
     * @var Array
     * @access private
     */
    
var $sbox1 = array(
        
0x008082000x000000000x000080000x00808202,
        
0x008080020x000082020x000000020x00008000,
        
0x000002000x008082000x008082020x00000200,
        
0x008002020x008080020x008000000x00000002,
        
0x000002020x008002000x008002000x00008200,
        
0x000082000x008080000x008080000x00800202,
        
0x000080020x008000020x008000020x00008002,
        
0x000000000x000002020x000082020x00800000,
        
0x000080000x008082020x000000020x00808000,
        
0x008082000x008000000x008000000x00000200,
        
0x008080020x000080000x000082000x00800002,
        
0x000002000x000000020x008002020x00008202,
        
0x008082020x000080020x008080000x00800202,
        
0x008000020x000002020x000082020x00808200,
        
0x000002020x008002000x008002000x00000000,
        
0x000080020x000082000x000000000x00808002
    
);

    
/**
     * Pre-permuted S-box2
     *
     * @var Array
     * @access private
     */
    
var $sbox2 = array(
        
0x400840100x400040000x000040000x00084010,
        
0x000800000x000000100x400800100x40004010,
        
0x400000100x400840100x400840000x40000000,
        
0x400040000x000800000x000000100x40080010,
        
0x000840000x000800100x400040100x00000000,
        
0x400000000x000040000x000840100x40080000,
        
0x000800100x400000100x000000000x00084000,
        
0x000040100x400840000x400800000x00004010,
        
0x000000000x000840100x400800100x00080000,
        
0x400040100x400800000x400840000x00004000,
        
0x400800000x400040000x000000100x40084010,
        
0x000840100x000000100x000040000x40000000,
        
0x000040100x400840000x000800000x40000010,
        
0x000800100x400040100x400000100x00080010,
        
0x000840000x000000000x400040000x00004010,
        
0x400000000x400800100x400840100x00084000
    
);

    
/**
     * Pre-permuted S-box3
     *
     * @var Array
     * @access private
     */
    
var $sbox3 = array(
        
0x000001040x040101000x000000000x04010004,
        
0x040001000x000000000x000101040x04000100,
        
0x000100040x040000040x040000040x00010000,
        
0x040101040x000100040x040100000x00000104,
        
0x040000000x000000040x040101000x00000100,
        
0x000101000x040100000x040100040x00010104,
        
0x040001040x000101000x000100000x04000104,
        
0x000000040x040101040x000001000x04000000,
        
0x040101000x040000000x000100040x00000104,
        
0x000100000x040101000x040001000x00000000,
        
0x000001000x000100040x040101040x04000100,
        
0x040000040x000001000x000000000x04010004,
        
0x040001040x000100000x040000000x04010104,
        
0x000000040x000101040x000101000x04000004,
        
0x040100000x040001040x000001040x04010000,
        
0x000101040x000000040x040100040x00010100
    
);

    
/**
     * Pre-permuted S-box4
     *
     * @var Array
     * @access private
     */
    
var $sbox4 = array(
        
0x804010000x800010400x800010400x00000040,
        
0x004010400x804000400x804000000x80001000,
        
0x000000000x004010000x004010000x80401040,
        
0x800000400x000000000x004000400x80400000,
        
0x800000000x000010000x004000000x80401000,
        
0x000000400x004000000x800010000x00001040,
        
0x804000400x800000000x000010400x00400040,
        
0x000010000x004010400x804010400x80000040,
        
0x004000400x804000000x004010000x80401040,
        
0x800000400x000000000x000000000x00401000,
        
0x000010400x004000400x804000400x80000000,
        
0x804010000x800010400x800010400x00000040,
        
0x804010400x800000400x800000000x00001000,
        
0x804000000x800010000x004010400x80400040,
        
0x800010000x000010400x004000000x80401000,
        
0x000000400x004000000x000010000x00401040
    
);

    
/**
     * Pre-permuted S-box5
     *
     * @var Array
     * @access private
     */
    
var $sbox5 = array(
        
0x000000800x010400800x010400000x21000080,
        
0x000400000x000000800x200000000x01040000,
        
0x200400800x000400000x010000800x20040080,
        
0x210000800x210400000x000400800x20000000,
        
0x010000000x200400000x200400000x00000000,
        
0x200000800x210400800x210400800x01000080,
        
0x210400000x200000800x000000000x21000000,
        
0x010400800x010000000x210000000x00040080,
        
0x000400000x210000800x000000800x01000000,
        
0x200000000x010400000x210000800x20040080,
        
0x010000800x200000000x210400000x01040080,
        
0x200400800x000000800x010000000x21040000,
        
0x210400800x000400800x210000000x21040080,
        
0x010400000x000000000x200400000x21000000,
        
0x000400800x010000800x200000800x00040000,
        
0x000000000x200400000x010400800x20000080
    
);

    
/**
     * Pre-permuted S-box6
     *
     * @var Array
     * @access private
     */
    
var $sbox6 = array(
        
0x100000080x102000000x000020000x10202008,
        
0x102000000x000000080x102020080x00200000,
        
0x100020000x002020080x002000000x10000008,
        
0x002000080x100020000x100000000x00002008,
        
0x000000000x002000080x100020080x00002000,
        
0x002020000x100020080x000000080x10200008,
        
0x102000080x000000000x002020080x10202000,
        
0x000020080x002020000x102020000x10000000,
        
0x100020000x000000080x102000080x00202000,
        
0x102020080x002000000x000020080x10000008,
        
0x002000000x100020000x100000000x00002008,
        
0x100000080x102020080x002020000x10200000,
        
0x002020080x102020000x000000000x10200008,
        
0x000000080x000020000x102000000x00202008,
        
0x000020000x002000080x100020080x00000000,
        
0x102020000x100000000x002000080x10002008
    
);

    
/**
     * Pre-permuted S-box7
     *
     * @var Array
     * @access private
     */
    
var $sbox7 = array(
        
0x001000000x021000010x020004010x00000000,
        
0x000004000x020004010x001004010x02100400,
        
0x021004010x001000000x000000000x02000001,
        
0x000000010x020000000x021000010x00000401,
        
0x020004000x001004010x001000010x02000400,
        
0x020000010x021000000x021004000x00100001,
        
0x021000000x000004000x000004010x02100401,
        
0x001004000x000000010x020000000x00100400,
        
0x020000000x001004000x001000000x02000401,
        
0x020004010x021000010x021000010x00000001,
        
0x001000010x020000000x020004000x00100000,
        
0x021004000x000004010x001004010x02100400,
        
0x000004010x020000010x021004010x02100000,
        
0x001004000x000000000x000000010x02100401,
        
0x000000000x001004010x021000000x00000400,
        
0x020000010x020004000x000004000x00100001
    
);

    
/**
     * Pre-permuted S-box8
     *
     * @var Array
     * @access private
     */
    
var $sbox8 = array(
        
0x080008200x000008000x000200000x08020820,
        
0x080000000x080008200x000000200x08000000,
        
0x000200200x080200000x080208200x00020800,
        
0x080208000x000208200x000008000x00000020,
        
0x080200000x080000200x080008000x00000820,
        
0x000208000x000200200x080200200x08020800,
        
0x000008200x000000000x000000000x08020020,
        
0x080000200x080008000x000208200x00020000,
        
0x000208200x000200000x080208000x00000800,
        
0x000000200x080200200x000008000x00020820,
        
0x080008000x000000200x080000200x08020000,
        
0x080200200x080000000x000200000x08000820,
        
0x000000000x080208200x000200200x08000020,
        
0x080200000x080008000x080008200x00000000,
        
0x080208200x000208000x000208000x00000820,
        
0x000008200x000200200x080000000x08020800
    
);

    
/**
     * Test for engine validity
     *
     * This is mainly just a wrapper to set things up for Crypt_Base::isValidEngine()
     *
     * @see Crypt_Base::isValidEngine()
     * @param Integer $engine
     * @access public
     * @return Boolean
     */
    
function isValidEngine($engine)
    {
        if (
$this->key_size_max == 8) {
            if (
$engine == CRYPT_ENGINE_OPENSSL) {
                
$this->cipher_name_openssl_ecb 'des-ecb';
                
$this->cipher_name_openssl 'des-' $this->_openssl_translate_mode();
            }
        }

        return 
parent::isValidEngine($engine);
    }

    
/**
     * Sets the key.
     *
     * Keys can be of any length.  DES, itself, uses 64-bit keys (eg. strlen($key) == 8), however, we
     * only use the first eight, if $key has more then eight characters in it, and pad $key with the
     * null byte if it is less then eight characters long.
     *
     * DES also requires that every eighth bit be a parity bit, however, we'll ignore that.
     *
     * If the key is not explicitly set, it'll be assumed to be all zero's.
     *
     * @see Crypt_Base::setKey()
     * @access public
     * @param String $key
     */
    
function setKey($key)
    {
        
// We check/cut here only up to max length of the key.
        // Key padding to the proper length will be done in _setupKey()
        
if (strlen($key) > $this->key_size_max) {
            
$key substr($key0$this->key_size_max);
        }

        
// Sets the key
        
parent::setKey($key);
    }

    
/**
     * Encrypts a block
     *
     * @see Crypt_Base::_encryptBlock()
     * @see Crypt_Base::encrypt()
     * @see Crypt_DES::encrypt()
     * @access private
     * @param String $in
     * @return String
     */
    
function _encryptBlock($in)
    {
        return 
$this->_processBlock($inCRYPT_DES_ENCRYPT);
    }

    
/**
     * Decrypts a block
     *
     * @see Crypt_Base::_decryptBlock()
     * @see Crypt_Base::decrypt()
     * @see Crypt_DES::decrypt()
     * @access private
     * @param String $in
     * @return String
     */
    
function _decryptBlock($in)
    {
        return 
$this->_processBlock($inCRYPT_DES_DECRYPT);
    }

    
/**
     * Encrypts or decrypts a 64-bit block
     *
     * $mode should be either CRYPT_DES_ENCRYPT or CRYPT_DES_DECRYPT.  See
     * {@link http://en.wikipedia.org/wiki/Image:Feistel.png Feistel.png} to get a general
     * idea of what this function does.
     *
     * @see Crypt_DES::_encryptBlock()
     * @see Crypt_DES::_decryptBlock()
     * @access private
     * @param String $block
     * @param Integer $mode
     * @return String
     */
    
function _processBlock($block$mode)
    {
        static 
$sbox1$sbox2$sbox3$sbox4$sbox5$sbox6$sbox7$sbox8$shuffleip$shuffleinvip;
        if (!
$sbox1) {
            
$sbox1 array_map("intval"$this->sbox1);
            
$sbox2 array_map("intval"$this->sbox2);
            
$sbox3 array_map("intval"$this->sbox3);
            
$sbox4 array_map("intval"$this->sbox4);
            
$sbox5 array_map("intval"$this->sbox5);
            
$sbox6 array_map("intval"$this->sbox6);
            
$sbox7 array_map("intval"$this->sbox7);
            
$sbox8 array_map("intval"$this->sbox8);
            
/* Merge $shuffle with $[inv]ipmap */
            
for ($i 0$i 256; ++$i) {
                
$shuffleip[]    =  $this->shuffle[$this->ipmap[$i]];
                
$shuffleinvip[] =  $this->shuffle[$this->invipmap[$i]];
            }
        }

        
$keys  $this->keys[$mode];
        
$ki    = -1;

        
// Do the initial IP permutation.
        
$t unpack('Nl/Nr'$block);
        list(
$l$r) = array($t['l'], $t['r']);
        
$block = ($shuffleip$r        0xFF] & "x80x80x80x80x80x80x80x80") |
                 (
$shuffleip[($r >>  8) & 0xFF] & "x40x40x40x40x40x40x40x40") |
                 (
$shuffleip[($r >> 16) & 0xFF] & "x20x20x20x20x20x20x20x20") |
                 (
$shuffleip[($r >> 24) & 0xFF] & "x10x10x10x10x10x10x10x10") |
                 (
$shuffleip$l        0xFF] & "x08x08x08x08x08x08x08x08") |
                 (
$shuffleip[($l >>  8) & 0xFF] & "x04x04x04x04x04x04x04x04") |
                 (
$shuffleip[($l >> 16) & 0xFF] & "x02x02x02x02x02x02x02x02") |
                 (
$shuffleip[($l >> 24) & 0xFF] & "x01x01x01x01x01x01x01x01");

        
// Extract L0 and R0.
        
$t unpack('Nl/Nr'$block);
        list(
$l$r) = array($t['l'], $t['r']);

        for (
$des_round 0$des_round $this->des_rounds; ++$des_round) {
            
// Perform the 16 steps.
            
for ($i 0$i 16$i++) {
                
// start of "the Feistel (F) function" - see the following URL:
                // http://en.wikipedia.org/wiki/Image:Data_Encryption_Standard_InfoBox_Diagram.png
                // Merge key schedule.
                
$b1 = (($r >>  3) & 0x1FFFFFFF) ^ ($r << 29) ^ $keys[++$ki];
                
$b2 = (($r >> 31) & 0x00000001) ^ ($r <<  1) ^ $keys[++$ki];

                
// S-box indexing.
                
$t $sbox1[($b1 >> 24) & 0x3F] ^ $sbox2[($b2 >> 24) & 0x3F] ^
                     
$sbox3[($b1 >> 16) & 0x3F] ^ $sbox4[($b2 >> 16) & 0x3F] ^
                     
$sbox5[($b1 >>  8) & 0x3F] ^ $sbox6[($b2 >>  8) & 0x3F] ^
                     
$sbox7$b1        0x3F] ^ $sbox8$b2        0x3F] ^ $l;
                
// end of "the Feistel (F) function"

                
$l $r;
                
$r $t;
            }

            
// Last step should not permute L & R.
            
$t $l;
            
$l $r;
            
$r $t;
        }

        
// Perform the inverse IP permutation.
        
return ($shuffleinvip[($r >> 24) & 0xFF] & "x80x80x80x80x80x80x80x80") |
               (
$shuffleinvip[($l >> 24) & 0xFF] & "x40x40x40x40x40x40x40x40") |
               (
$shuffleinvip[($r >> 16) & 0xFF] & "x20x20x20x20x20x20x20x20") |
               (
$shuffleinvip[($l >> 16) & 0xFF] & "x10x10x10x10x10x10x10x10") |
               (
$shuffleinvip[($r >>  8) & 0xFF] & "x08x08x08x08x08x08x08x08") |
               (
$shuffleinvip[($l >>  8) & 0xFF] & "x04x04x04x04x04x04x04x04") |
               (
$shuffleinvip$r        0xFF] & "x02x02x02x02x02x02x02x02") |
               (
$shuffleinvip$l        0xFF] & "x01x01x01x01x01x01x01x01");
    }

    
/**
     * Creates the key schedule
     *
     * @see Crypt_Base::_setupKey()
     * @access private
     */
    
function _setupKey()
    {
        if (isset(
$this->kl['key']) && $this->key === $this->kl['key'] && $this->des_rounds === $this->kl['des_rounds']) {
            
// already expanded
            
return;
        }
        
$this->kl = array('key' => $this->key'des_rounds' => $this->des_rounds);

        static 
$shifts = array( // number of key bits shifted per round
            
1122222212222221
        
);

        static 
$pc1map = array(
            
0x000x000x080x080x040x040x0C0x0C,
            
0x020x020x0A0x0A0x060x060x0E0x0E,
            
0x100x100x180x180x140x140x1C0x1C,
            
0x120x120x1A0x1A0x160x160x1E0x1E,
            
0x200x200x280x280x240x240x2C0x2C,
            
0x220x220x2A0x2A0x260x260x2E0x2E,
            
0x300x300x380x380x340x340x3C0x3C,
            
0x320x320x3A0x3A0x360x360x3E0x3E,
            
0x400x400x480x480x440x440x4C0x4C,
            
0x420x420x4A0x4A0x460x460x4E0x4E,
            
0x500x500x580x580x540x540x5C0x5C,
            
0x520x520x5A0x5A0x560x560x5E0x5E,
            
0x600x600x680x680x640x640x6C0x6C,
            
0x620x620x6A0x6A0x660x660x6E0x6E,
            
0x700x700x780x780x740x740x7C0x7C,
            
0x720x720x7A0x7A0x760x760x7E0x7E,
            
0x800x800x880x880x840x840x8C0x8C,
            
0x820x820x8A0x8A0x860x860x8E0x8E,
            
0x900x900x980x980x940x940x9C0x9C,
            
0x920x920x9A0x9A0x960x960x9E0x9E,
            
0xA00xA00xA80xA80xA40xA40xAC0xAC,
            
0xA20xA20xAA0xAA0xA60xA60xAE0xAE,
            
0xB00xB00xB80xB80xB40xB40xBC0xBC,
            
0xB20xB20xBA0xBA0xB60xB60xBE0xBE,
            
0xC00xC00xC80xC80xC40xC40xCC0xCC,
            
0xC20xC20xCA0xCA0xC60xC60xCE0xCE,
            
0xD00xD00xD80xD80xD40xD40xDC0xDC,
            
0xD20xD20xDA0xDA0xD60xD60xDE0xDE,
            
0xE00xE00xE80xE80xE40xE40xEC0xEC,
            
0xE20xE20xEA0xEA0xE60xE60xEE0xEE,
            
0xF00xF00xF80xF80xF40xF40xFC0xFC,
            
0xF20xF20xFA0xFA0xF60xF60xFE0xFE
        
);

        
// Mapping tables for the PC-2 transformation.
        
static $pc2mapc1 = array(
            
0x000000000x000004000x002000000x00200400,
            
0x000000010x000004010x002000010x00200401,
            
0x020000000x020004000x022000000x02200400,
            
0x020000010x020004010x022000010x02200401
        
);
        static 
$pc2mapc2 = array(
            
0x000000000x000008000x080000000x08000800,
            
0x000100000x000108000x080100000x08010800,
            
0x000000000x000008000x080000000x08000800,
            
0x000100000x000108000x080100000x08010800,
            
0x000001000x000009000x080001000x08000900,
            
0x000101000x000109000x080101000x08010900,
            
0x000001000x000009000x080001000x08000900,
            
0x000101000x000109000x080101000x08010900,
            
0x000000100x000008100x080000100x08000810,
            
0x000100100x000108100x080100100x08010810,
            
0x000000100x000008100x080000100x08000810,
            
0x000100100x000108100x080100100x08010810,
            
0x000001100x000009100x080001100x08000910,
            
0x000101100x000109100x080101100x08010910,
            
0x000001100x000009100x080001100x08000910,
            
0x000101100x000109100x080101100x08010910,
            
0x000400000x000408000x080400000x08040800,
            
0x000500000x000508000x080500000x08050800,
            
0x000400000x000408000x080400000x08040800,
            
0x000500000x000508000x080500000x08050800,
            
0x000401000x000409000x080401000x08040900,
            
0x000501000x000509000x080501000x08050900,
            
0x000401000x000409000x080401000x08040900,
            
0x000501000x000509000x080501000x08050900,
            
0x000400100x000408100x080400100x08040810,
            
0x000500100x000508100x080500100x08050810,
            
0x000400100x000408100x080400100x08040810,
            
0x000500100x000508100x080500100x08050810,
            
0x000401100x000409100x080401100x08040910,
            
0x000501100x000509100x080501100x08050910,
            
0x000401100x000409100x080401100x08040910,
            
0x000501100x000509100x080501100x08050910,
            
0x010000000x010008000x090000000x09000800,
            
0x010100000x010108000x090100000x09010800,
            
0x010000000x010008000x090000000x09000800,
            
0x010100000x010108000x090100000x09010800,
            
0x010001000x010009000x090001000x09000900,
            
0x010101000x010109000x090101000x09010900,
            
0x010001000x010009000x090001000x09000900,
            
0x010101000x010109000x090101000x09010900,
            
0x010000100x010008100x090000100x09000810,
            
0x010100100x010108100x090100100x09010810,
            
0x010000100x010008100x090000100x09000810,
            
0x010100100x010108100x090100100x09010810,
            
0x010001100x010009100x090001100x09000910,
            
0x010101100x010109100x090101100x09010910,
            
0x010001100x010009100x090001100x09000910,
            
0x010101100x010109100x090101100x09010910,
            
0x010400000x010408000x090400000x09040800,
            
0x010500000x010508000x090500000x09050800,
            
0x010400000x010408000x090400000x09040800,
            
0x010500000x010508000x090500000x09050800,
            
0x010401000x010409000x090401000x09040900,
            
0x010501000x010509000x090501000x09050900,
            
0x010401000x010409000x090401000x09040900,
            
0x010501000x010509000x090501000x09050900,
            
0x010400100x010408100x090400100x09040810,
            
0x010500100x010508100x090500100x09050810,
            
0x010400100x010408100x090400100x09040810,
            
0x010500100x010508100x090500100x09050810,
            
0x010401100x010409100x090401100x09040910,
            
0x010501100x010509100x090501100x09050910,
            
0x010401100x010409100x090401100x09040910,
            
0x010501100x010509100x090501100x09050910
        
);
        static 
$pc2mapc3 = array(
            
0x000000000x000000040x000010000x00001004,
            
0x000000000x000000040x000010000x00001004,
            
0x100000000x100000040x100010000x10001004,
            
0x100000000x100000040x100010000x10001004,
            
0x000000200x000000240x000010200x00001024,
            
0x000000200x000000240x000010200x00001024,
            
0x100000200x100000240x100010200x10001024,
            
0x100000200x100000240x100010200x10001024,
            
0x000800000x000800040x000810000x00081004,
            
0x000800000x000800040x000810000x00081004,
            
0x100800000x100800040x100810000x10081004,
            
0x100800000x100800040x100810000x10081004,
            
0x000800200x000800240x000810200x00081024,
            
0x000800200x000800240x000810200x00081024,
            
0x100800200x100800240x100810200x10081024,
            
0x100800200x100800240x100810200x10081024,
            
0x200000000x200000040x200010000x20001004,
            
0x200000000x200000040x200010000x20001004,
            
0x300000000x300000040x300010000x30001004,
            
0x300000000x300000040x300010000x30001004,
            
0x200000200x200000240x200010200x20001024,
            
0x200000200x200000240x200010200x20001024,
            
0x300000200x300000240x300010200x30001024,
            
0x300000200x300000240x300010200x30001024,
            
0x200800000x200800040x200810000x20081004,
            
0x200800000x200800040x200810000x20081004,
            
0x300800000x300800040x300810000x30081004,
            
0x300800000x300800040x300810000x30081004,
            
0x200800200x200800240x200810200x20081024,
            
0x200800200x200800240x200810200x20081024,
            
0x300800200x300800240x300810200x30081024,
            
0x300800200x300800240x300810200x30081024,
            
0x000000020x000000060x000010020x00001006,
            
0x000000020x000000060x000010020x00001006,
            
0x100000020x100000060x100010020x10001006,
            
0x100000020x100000060x100010020x10001006,
            
0x000000220x000000260x000010220x00001026,
            
0x000000220x000000260x000010220x00001026,
            
0x100000220x100000260x100010220x10001026,
            
0x100000220x100000260x100010220x10001026,
            
0x000800020x000800060x000810020x00081006,
            
0x000800020x000800060x000810020x00081006,
            
0x100800020x100800060x100810020x10081006,
            
0x100800020x100800060x100810020x10081006,
            
0x000800220x000800260x000810220x00081026,
            
0x000800220x000800260x000810220x00081026,
            
0x100800220x100800260x100810220x10081026,
            
0x100800220x100800260x100810220x10081026,
            
0x200000020x200000060x200010020x20001006,
            
0x200000020x200000060x200010020x20001006,
            
0x300000020x300000060x300010020x30001006,
            
0x300000020x300000060x300010020x30001006,
            
0x200000220x200000260x200010220x20001026,
            
0x200000220x200000260x200010220x20001026,
            
0x300000220x300000260x300010220x30001026,
            
0x300000220x300000260x300010220x30001026,
            
0x200800020x200800060x200810020x20081006,
            
0x200800020x200800060x200810020x20081006,
            
0x300800020x300800060x300810020x30081006,
            
0x300800020x300800060x300810020x30081006,
            
0x200800220x200800260x200810220x20081026,
            
0x200800220x200800260x200810220x20081026,
            
0x300800220x300800260x300810220x30081026,
            
0x300800220x300800260x300810220x30081026
        
);
        static 
$pc2mapc4 = array(
            
0x000000000x001000000x000000080x00100008,
            
0x000002000x001002000x000002080x00100208,
            
0x000000000x001000000x000000080x00100008,
            
0x000002000x001002000x000002080x00100208,
            
0x040000000x041000000x040000080x04100008,
            
0x040002000x041002000x040002080x04100208,
            
0x040000000x041000000x040000080x04100008,
            
0x040002000x041002000x040002080x04100208,
            
0x000020000x001020000x000020080x00102008,
            
0x000022000x001022000x000022080x00102208,
            
0x000020000x001020000x000020080x00102008,
            
0x000022000x001022000x000022080x00102208,
            
0x040020000x041020000x040020080x04102008,
            
0x040022000x041022000x040022080x04102208,
            
0x040020000x041020000x040020080x04102008,
            
0x040022000x041022000x040022080x04102208,
            
0x000000000x001000000x000000080x00100008,
            
0x000002000x001002000x000002080x00100208,
            
0x000000000x001000000x000000080x00100008,
            
0x000002000x001002000x000002080x00100208,
            
0x040000000x041000000x040000080x04100008,
            
0x040002000x041002000x040002080x04100208,
            
0x040000000x041000000x040000080x04100008,
            
0x040002000x041002000x040002080x04100208,
            
0x000020000x001020000x000020080x00102008,
            
0x000022000x001022000x000022080x00102208,
            
0x000020000x001020000x000020080x00102008,
            
0x000022000x001022000x000022080x00102208,
            
0x040020000x041020000x040020080x04102008,
            
0x040022000x041022000x040022080x04102208,
            
0x040020000x041020000x040020080x04102008,
            
0x040022000x041022000x040022080x04102208,
            
0x000200000x001200000x000200080x00120008,
            
0x000202000x001202000x000202080x00120208,
            
0x000200000x001200000x000200080x00120008,
            
0x000202000x001202000x000202080x00120208,
            
0x040200000x041200000x040200080x04120008,
            
0x040202000x041202000x040202080x04120208,
            
0x040200000x041200000x040200080x04120008,
            
0x040202000x041202000x040202080x04120208,
            
0x000220000x001220000x000220080x00122008,
            
0x000222000x001222000x000222080x00122208,
            
0x000220000x001220000x000220080x00122008,
            
0x000222000x001222000x000222080x00122208,
            
0x040220000x041220000x040220080x04122008,
            
0x040222000x041222000x040222080x04122208,
            
0x040220000x041220000x040220080x04122008,
            
0x040222000x041222000x040222080x04122208,
            
0x000200000x001200000x000200080x00120008,
            
0x000202000x001202000x000202080x00120208,
            
0x000200000x001200000x000200080x00120008,
            
0x000202000x001202000x000202080x00120208,
            
0x040200000x041200000x040200080x04120008,
            
0x040202000x041202000x040202080x04120208,
            
0x040200000x041200000x040200080x04120008,
            
0x040202000x041202000x040202080x04120208,
            
0x000220000x001220000x000220080x00122008,
            
0x000222000x001222000x000222080x00122208,
            
0x000220000x001220000x000220080x00122008,
            
0x000222000x001222000x000222080x00122208,
            
0x040220000x041220000x040220080x04122008,
            
0x040222000x041222000x040222080x04122208,
            
0x040220000x041220000x040220080x04122008,
            
0x040222000x041222000x040222080x04122208
        
);
        static 
$pc2mapd1 = array(
            
0x000000000x000000010x080000000x08000001,
            
0x002000000x002000010x082000000x08200001,
            
0x000000020x000000030x080000020x08000003,
            
0x002000020x002000030x082000020x08200003
        
);
        static 
$pc2mapd2 = array(
            
0x000000000x001000000x000008000x00100800,
            
0x000000000x001000000x000008000x00100800,
            
0x040000000x041000000x040008000x04100800,
            
0x040000000x041000000x040008000x04100800,
            
0x000000040x001000040x000008040x00100804,
            
0x000000040x001000040x000008040x00100804,
            
0x040000040x041000040x040008040x04100804,
            
0x040000040x041000040x040008040x04100804,
            
0x000000000x001000000x000008000x00100800,
            
0x000000000x001000000x000008000x00100800,
            
0x040000000x041000000x040008000x04100800,
            
0x040000000x041000000x040008000x04100800,
            
0x000000040x001000040x000008040x00100804,
            
0x000000040x001000040x000008040x00100804,
            
0x040000040x041000040x040008040x04100804,
            
0x040000040x041000040x040008040x04100804,
            
0x000002000x001002000x00000A000x00100A00,
            
0x000002000x001002000x00000A000x00100A00,
            
0x040002000x041002000x04000A000x04100A00,
            
0x040002000x041002000x04000A000x04100A00,
            
0x000002040x001002040x00000A040x00100A04,
            
0x000002040x001002040x00000A040x00100A04,
            
0x040002040x041002040x04000A040x04100A04,
            
0x040002040x041002040x04000A040x04100A04,
            
0x000002000x001002000x00000A000x00100A00,
            
0x000002000x001002000x00000A000x00100A00,
            
0x040002000x041002000x04000A000x04100A00,
            
0x040002000x041002000x04000A000x04100A00,
            
0x000002040x001002040x00000A040x00100A04,
            
0x000002040x001002040x00000A040x00100A04,
            
0x040002040x041002040x04000A040x04100A04,
            
0x040002040x041002040x04000A040x04100A04,
            
0x000200000x001200000x000208000x00120800,
            
0x000200000x001200000x000208000x00120800,
            
0x040200000x041200000x040208000x04120800,
            
0x040200000x041200000x040208000x04120800,
            
0x000200040x001200040x000208040x00120804,
            
0x000200040x001200040x000208040x00120804,
            
0x040200040x041200040x040208040x04120804,
            
0x040200040x041200040x040208040x04120804,
            
0x000200000x001200000x000208000x00120800,
            
0x000200000x001200000x000208000x00120800,
            
0x040200000x041200000x040208000x04120800,
            
0x040200000x041200000x040208000x04120800,
            
0x000200040x001200040x000208040x00120804,
            
0x000200040x001200040x000208040x00120804,
            
0x040200040x041200040x040208040x04120804,
            
0x040200040x041200040x040208040x04120804,
            
0x000202000x001202000x00020A000x00120A00,
            
0x000202000x001202000x00020A000x00120A00,
            
0x040202000x041202000x04020A000x04120A00,
            
0x040202000x041202000x04020A000x04120A00,
            
0x000202040x001202040x00020A040x00120A04,
            
0x000202040x001202040x00020A040x00120A04,
            
0x040202040x041202040x04020A040x04120A04,
            
0x040202040x041202040x04020A040x04120A04,
            
0x000202000x001202000x00020A000x00120A00,
            
0x000202000x001202000x00020A000x00120A00,
            
0x040202000x041202000x04020A000x04120A00,
            
0x040202000x041202000x04020A000x04120A00,
            
0x000202040x001202040x00020A040x00120A04,
            
0x000202040x001202040x00020A040x00120A04,
            
0x040202040x041202040x04020A040x04120A04,
            
0x040202040x041202040x04020A040x04120A04
        
);
        static 
$pc2mapd3 = array(
            
0x000000000x000100000x020000000x02010000,
            
0x000000200x000100200x020000200x02010020,
            
0x000400000x000500000x020400000x02050000,
            
0x000400200x000500200x020400200x02050020,
            
0x000020000x000120000x020020000x02012000,
            
0x000020200x000120200x020020200x02012020,
            
0x000420000x000520000x020420000x02052000,
            
0x000420200x000520200x020420200x02052020,
            
0x000000000x000100000x020000000x02010000,
            
0x000000200x000100200x020000200x02010020,
            
0x000400000x000500000x020400000x02050000,
            
0x000400200x000500200x020400200x02050020,
            
0x000020000x000120000x020020000x02012000,
            
0x000020200x000120200x020020200x02012020,
            
0x000420000x000520000x020420000x02052000,
            
0x000420200x000520200x020420200x02052020,
            
0x000000100x000100100x020000100x02010010,
            
0x000000300x000100300x020000300x02010030,
            
0x000400100x000500100x020400100x02050010,
            
0x000400300x000500300x020400300x02050030,
            
0x000020100x000120100x020020100x02012010,
            
0x000020300x000120300x020020300x02012030,
            
0x000420100x000520100x020420100x02052010,
            
0x000420300x000520300x020420300x02052030,
            
0x000000100x000100100x020000100x02010010,
            
0x000000300x000100300x020000300x02010030,
            
0x000400100x000500100x020400100x02050010,
            
0x000400300x000500300x020400300x02050030,
            
0x000020100x000120100x020020100x02012010,
            
0x000020300x000120300x020020300x02012030,
            
0x000420100x000520100x020420100x02052010,
            
0x000420300x000520300x020420300x02052030,
            
0x200000000x200100000x220000000x22010000,
            
0x200000200x200100200x220000200x22010020,
            
0x200400000x200500000x220400000x22050000,
            
0x200400200x200500200x220400200x22050020,
            
0x200020000x200120000x220020000x22012000,
            
0x200020200x200120200x220020200x22012020,
            
0x200420000x200520000x220420000x22052000,
            
0x200420200x200520200x220420200x22052020,
            
0x200000000x200100000x220000000x22010000,
            
0x200000200x200100200x220000200x22010020,
            
0x200400000x200500000x220400000x22050000,
            
0x200400200x200500200x220400200x22050020,
            
0x200020000x200120000x220020000x22012000,
            
0x200020200x200120200x220020200x22012020,
            
0x200420000x200520000x220420000x22052000,
            
0x200420200x200520200x220420200x22052020,
            
0x200000100x200100100x220000100x22010010,
            
0x200000300x200100300x220000300x22010030,
            
0x200400100x200500100x220400100x22050010,
            
0x200400300x200500300x220400300x22050030,
            
0x200020100x200120100x220020100x22012010,
            
0x200020300x200120300x220020300x22012030,
            
0x200420100x200520100x220420100x22052010,
            
0x200420300x200520300x220420300x22052030,
            
0x200000100x200100100x220000100x22010010,
            
0x200000300x200100300x220000300x22010030,
            
0x200400100x200500100x220400100x22050010,
            
0x200400300x200500300x220400300x22050030,
            
0x200020100x200120100x220020100x22012010,
            
0x200020300x200120300x220020300x22012030,
            
0x200420100x200520100x220420100x22052010,
            
0x200420300x200520300x220420300x22052030
        
);
        static 
$pc2mapd4 = array(
            
0x000000000x000004000x010000000x01000400,
            
0x000000000x000004000x010000000x01000400,
            
0x000001000x000005000x010001000x01000500,
            
0x000001000x000005000x010001000x01000500,
            
0x100000000x100004000x110000000x11000400,
            
0x100000000x100004000x110000000x11000400,
            
0x100001000x100005000x110001000x11000500,
            
0x100001000x100005000x110001000x11000500,
            
0x000800000x000804000x010800000x01080400,
            
0x000800000x000804000x010800000x01080400,
            
0x000801000x000805000x010801000x01080500,
            
0x000801000x000805000x010801000x01080500,
            
0x100800000x100804000x110800000x11080400,
            
0x100800000x100804000x110800000x11080400,
            
0x100801000x100805000x110801000x11080500,
            
0x100801000x100805000x110801000x11080500,
            
0x000000080x000004080x010000080x01000408,
            
0x000000080x000004080x010000080x01000408,
            
0x000001080x000005080x010001080x01000508,
            
0x000001080x000005080x010001080x01000508,
            
0x100000080x100004080x110000080x11000408,
            
0x100000080x100004080x110000080x11000408,
            
0x100001080x100005080x110001080x11000508,
            
0x100001080x100005080x110001080x11000508,
            
0x000800080x000804080x010800080x01080408,
            
0x000800080x000804080x010800080x01080408,
            
0x000801080x000805080x010801080x01080508,
            
0x000801080x000805080x010801080x01080508,
            
0x100800080x100804080x110800080x11080408,
            
0x100800080x100804080x110800080x11080408,
            
0x100801080x100805080x110801080x11080508,
            
0x100801080x100805080x110801080x11080508,
            
0x000010000x000014000x010010000x01001400,
            
0x000010000x000014000x010010000x01001400,
            
0x000011000x000015000x010011000x01001500,
            
0x000011000x000015000x010011000x01001500,
            
0x100010000x100014000x110010000x11001400,
            
0x100010000x100014000x110010000x11001400,
            
0x100011000x100015000x110011000x11001500,
            
0x100011000x100015000x110011000x11001500,
            
0x000810000x000814000x010810000x01081400,
            
0x000810000x000814000x010810000x01081400,
            
0x000811000x000815000x010811000x01081500,
            
0x000811000x000815000x010811000x01081500,
            
0x100810000x100814000x110810000x11081400,
            
0x100810000x100814000x110810000x11081400,
            
0x100811000x100815000x110811000x11081500,
            
0x100811000x100815000x110811000x11081500,
            
0x000010080x000014080x010010080x01001408,
            
0x000010080x000014080x010010080x01001408,
            
0x000011080x000015080x010011080x01001508,
            
0x000011080x000015080x010011080x01001508,
            
0x100010080x100014080x110010080x11001408,
            
0x100010080x100014080x110010080x11001408,
            
0x100011080x100015080x110011080x11001508,
            
0x100011080x100015080x110011080x11001508,
            
0x000810080x000814080x010810080x01081408,
            
0x000810080x000814080x010810080x01081408,
            
0x000811080x000815080x010811080x01081508,
            
0x000811080x000815080x010811080x01081508,
            
0x100810080x100814080x110810080x11081408,
            
0x100810080x100814080x110810080x11081408,
            
0x100811080x100815080x110811080x11081508,
            
0x100811080x100815080x110811080x11081508
        
);

        
$keys = array();
        for (
$des_round 0$des_round $this->des_rounds; ++$des_round) {
            
// pad the key and remove extra characters as appropriate.
            
$key str_pad(substr($this->key$des_round 88), 8"");

            
// Perform the PC/1 transformation and compute C and D.
            
$t unpack('Nl/Nr'$key);
            list(
$l$r) = array($t['l'], $t['r']);
            
$key = ($this->shuffle[$pc1map$r        0xFF]] & "x80x80x80x80x80x80x80x00") |
                   (
$this->shuffle[$pc1map[($r >>  8) & 0xFF]] & "x40x40x40x40x40x40x40x00") |
                   (
$this->shuffle[$pc1map[($r >> 16) & 0xFF]] & "x20x20x20x20x20x20x20x00") |
                   (
$this->shuffle[$pc1map[($r >> 24) & 0xFF]] & "x10x10x10x10x10x10x10x00") |
                   (
$this->shuffle[$pc1map$l        0xFF]] & "x08x08x08x08x08x08x08x00") |
                   (
$this->shuffle[$pc1map[($l >>  8) & 0xFF]] & "x04x04x04x04x04x04x04x00") |
                   (
$this->shuffle[$pc1map[($l >> 16) & 0xFF]] & "x02x02x02x02x02x02x02x00") |
                   (
$this->shuffle[$pc1map[($l >> 24) & 0xFF]] & "x01x01x01x01x01x01x01x00");
            
$key unpack('Nc/Nd'$key);
            
$c = ( $key['c'] >> 4) & 0x0FFFFFFF;
            
$d = (($key['d'] >> 4) & 0x0FFFFFF0) | ($key['c'] & 0x0F);

            
$keys[$des_round] = array(
                
CRYPT_DES_ENCRYPT => array(),
                
CRYPT_DES_DECRYPT => array_fill(0320)
            );
            for (
$i 0$ki 31$i 16; ++$i$ki-= 2) {
                
$c <<= $shifts[$i];
                
$c = ($c | ($c >> 28)) & 0x0FFFFFFF;
                
$d <<= $shifts[$i];
                
$d = ($d | ($d >> 28)) & 0x0FFFFFFF;

                
// Perform the PC-2 transformation.
                
$cp $pc2mapc1$c >> 24        ] | $pc2mapc2[($c >> 16) & 0xFF] |
                      
$pc2mapc3[($c >>  8) & 0xFF] | $pc2mapc4$c        0xFF];
                
$dp $pc2mapd1$d >> 24        ] | $pc2mapd2[($d >> 16) & 0xFF] |
                      
$pc2mapd3[($d >>  8) & 0xFF] | $pc2mapd4$d        0xFF];

                
// Reorder: odd bytes/even bytes. Push the result in key schedule.
                
$val1 = ( $cp        0xFF000000) | (($cp <<  8) & 0x00FF0000) |
                        ((
$dp >> 16) & 0x0000FF00) | (($dp >>  8) & 0x000000FF);
                
$val2 = (($cp <<  8) & 0xFF000000) | (($cp << 16) & 0x00FF0000) |
                        ((
$dp >>  8) & 0x0000FF00) | ( $dp        0x000000FF);
                
$keys[$des_round][CRYPT_DES_ENCRYPT][       ] = $val1;
                
$keys[$des_round][CRYPT_DES_DECRYPT][$ki 1] = $val1;
                
$keys[$des_round][CRYPT_DES_ENCRYPT][       ] = $val2;
                
$keys[$des_round][CRYPT_DES_DECRYPT][$ki    ] = $val2;
            }
        }

        switch (
$this->des_rounds) {
            case 
3// 3DES keys
                
$this->keys = array(
                    
CRYPT_DES_ENCRYPT => array_merge(
                        
$keys[0][CRYPT_DES_ENCRYPT],
                        
$keys[1][CRYPT_DES_DECRYPT],
                        
$keys[2][CRYPT_DES_ENCRYPT]
                    ),
                    
CRYPT_DES_DECRYPT => array_merge(
                        
$keys[2][CRYPT_DES_DECRYPT],
                        
$keys[1][CRYPT_DES_ENCRYPT],
                        
$keys[0][CRYPT_DES_DECRYPT]
                    )
                );
                break;
            
// case 1: // DES keys
            
default:
                
$this->keys = array(
                    
CRYPT_DES_ENCRYPT => $keys[0][CRYPT_DES_ENCRYPT],
                    
CRYPT_DES_DECRYPT => $keys[0][CRYPT_DES_DECRYPT]
                );
        }
    }

    
/**
     * Setup the performance-optimized function for de/encrypt()
     *
     * @see Crypt_Base::_setupInlineCrypt()
     * @access private
     */
    
function _setupInlineCrypt()
    {
        
$lambda_functions =& Crypt_DES::_getLambdaFunctions();

        
// Engine configuration for:
        // -  DES ($des_rounds == 1) or
        // - 3DES ($des_rounds == 3)
        
$des_rounds $this->des_rounds;

        
// We create max. 10 hi-optimized code for memory reason. Means: For each $key one ultra fast inline-crypt function.
        // (Currently, for Crypt_DES,       one generated $lambda_function cost on php5.5@32bit ~135kb unfreeable mem and ~230kb on php5.5@64bit)
        // (Currently, for Crypt_TripleDES, one generated $lambda_function cost on php5.5@32bit ~240kb unfreeable mem and ~340kb on php5.5@64bit)
        // After that, we'll still create very fast optimized code but not the hi-ultimative code, for each $mode one
        
$gen_hi_opt_code = (bool)( count($lambda_functions) < 10 );

        
// Generation of a uniqe hash for our generated code
        
$code_hash "Crypt_DES, $des_rounds{$this->mode}";
        if (
$gen_hi_opt_code) {
            
// For hi-optimized code, we create for each combination of
            // $mode, $des_rounds and $this->key its own encrypt/decrypt function.
            // After max 10 hi-optimized functions, we create generic
            // (still very fast.. but not ultra) functions for each $mode/$des_rounds
            // Currently 2 * 5 generic functions will be then max. possible.
            
$code_hash str_pad($code_hash32) . $this->_hashInlineCryptFunction($this->key);
        }

        
// Is there a re-usable $lambda_functions in there? If not, we have to create it.
        
if (!isset($lambda_functions[$code_hash])) {
            
// Init code for both, encrypt and decrypt.
            
$init_crypt 'static $sbox1, $sbox2, $sbox3, $sbox4, $sbox5, $sbox6, $sbox7, $sbox8, $shuffleip, $shuffleinvip;
                if (!$sbox1) {
                    $sbox1 = array_map("intval", $self->sbox1);
                    $sbox2 = array_map("intval", $self->sbox2);
                    $sbox3 = array_map("intval", $self->sbox3);
                    $sbox4 = array_map("intval", $self->sbox4);
                    $sbox5 = array_map("intval", $self->sbox5);
                    $sbox6 = array_map("intval", $self->sbox6);
                    $sbox7 = array_map("intval", $self->sbox7);
                    $sbox8 = array_map("intval", $self->sbox8);'
                    
/* Merge $shuffle with $[inv]ipmap */ '
                    for ($i = 0; $i < 256; ++$i) {
                        $shuffleip[]    =  $self->shuffle[$self->ipmap[$i]];
                        $shuffleinvip[] =  $self->shuffle[$self->invipmap[$i]];
                    }
                }
            '
;

            switch (
true) {
                case 
$gen_hi_opt_code:
                    
// In Hi-optimized code mode, we use our [3]DES key schedule as hardcoded integers.
                    // No futher initialisation of the $keys schedule is necessary.
                    // That is the extra performance boost.
                    
$k = array(
                        
CRYPT_DES_ENCRYPT => $this->keys[CRYPT_DES_ENCRYPT],
                        
CRYPT_DES_DECRYPT => $this->keys[CRYPT_DES_DECRYPT]
                    );
                    
$init_encrypt '';
                    
$init_decrypt '';
                    break;
                default:
                    
// In generic optimized code mode, we have to use, as the best compromise [currently],
                    // our key schedule as $ke/$kd arrays. (with hardcoded indexes...)
                    
$k = array(
                        
CRYPT_DES_ENCRYPT => array(),
                        
CRYPT_DES_DECRYPT => array()
                    );
                    for (
$i 0$c count($this->keys[CRYPT_DES_ENCRYPT]); $i $c; ++$i) {
                        
$k[CRYPT_DES_ENCRYPT][$i] = '$ke[' $i ']';
                        
$k[CRYPT_DES_DECRYPT][$i] = '$kd[' $i ']';
                    }
                    
$init_encrypt '$ke = $self->keys[CRYPT_DES_ENCRYPT];';
                    
$init_decrypt '$kd = $self->keys[CRYPT_DES_DECRYPT];';
                    break;
            }

            
// Creating code for en- and decryption.
            
$crypt_block = array();
            foreach (array(
CRYPT_DES_ENCRYPTCRYPT_DES_DECRYPT) as $c) {
                
/* Do the initial IP permutation. */
                
$crypt_block[$c] = '
                    $in = unpack("N*", $in);
                    $l  = $in[1];
                    $r  = $in[2];
                    $in = unpack("N*",
                        ($shuffleip[ $r        & 0xFF] & "x80x80x80x80x80x80x80x80") |
                        ($shuffleip[($r >>  8) & 0xFF] & "x40x40x40x40x40x40x40x40") |
                        ($shuffleip[($r >> 16) & 0xFF] & "x20x20x20x20x20x20x20x20") |
                        ($shuffleip[($r >> 24) & 0xFF] & "x10x10x10x10x10x10x10x10") |
                        ($shuffleip[ $l        & 0xFF] & "x08x08x08x08x08x08x08x08") |
                        ($shuffleip[($l >>  8) & 0xFF] & "x04x04x04x04x04x04x04x04") |
                        ($shuffleip[($l >> 16) & 0xFF] & "x02x02x02x02x02x02x02x02") |
                        ($shuffleip[($l >> 24) & 0xFF] & "x01x01x01x01x01x01x01x01")
                    );
                    ' 
/* Extract L0 and R0 */ '
                    $l = $in[1];
                    $r = $in[2];
                '
;

                
$l '$l';
                
$r '$r';

                
// Perform DES or 3DES.
                
for ($ki = -1$des_round 0$des_round $des_rounds; ++$des_round) {
                    
// Perform the 16 steps.
                    
for ($i 0$i 16; ++$i) {
                        
// start of "the Feistel (F) function" - see the following URL:
                        // http://en.wikipedia.org/wiki/Image:Data_Encryption_Standard_InfoBox_Diagram.png
                        // Merge key schedule.
                        
$crypt_block[$c].= '
                            $b1 = ((' 
$r ' >>  3) & 0x1FFFFFFF)  ^ (' $r ' << 29) ^ ' $k[$c][++$ki] . ';
                            $b2 = ((' 
$r ' >> 31) & 0x00000001)  ^ (' $r ' <<  1) ^ ' $k[$c][++$ki] . ';' .
                            
/* S-box indexing. */
                            
$l ' = $sbox1[($b1 >> 24) & 0x3F] ^ $sbox2[($b2 >> 24) & 0x3F] ^
                                     $sbox3[($b1 >> 16) & 0x3F] ^ $sbox4[($b2 >> 16) & 0x3F] ^
                                     $sbox5[($b1 >>  8) & 0x3F] ^ $sbox6[($b2 >>  8) & 0x3F] ^
                                     $sbox7[ $b1        & 0x3F] ^ $sbox8[ $b2        & 0x3F] ^ ' 
$l ';
                        '
;
                        
// end of "the Feistel (F) function"

                        // swap L & R
                        
list($l$r) = array($r$l);
                    }
                    list(
$l$r) = array($r$l);
                }

                
// Perform the inverse IP permutation.
                
$crypt_block[$c].= '$in =
                    ($shuffleinvip[($l >> 24) & 0xFF] & "x80x80x80x80x80x80x80x80") |
                    ($shuffleinvip[($r >> 24) & 0xFF] & "x40x40x40x40x40x40x40x40") |
                    ($shuffleinvip[($l >> 16) & 0xFF] & "x20x20x20x20x20x20x20x20") |
                    ($shuffleinvip[($r >> 16) & 0xFF] & "x10x10x10x10x10x10x10x10") |
                    ($shuffleinvip[($l >>  8) & 0xFF] & "x08x08x08x08x08x08x08x08") |
                    ($shuffleinvip[($r >>  8) & 0xFF] & "x04x04x04x04x04x04x04x04") |
                    ($shuffleinvip[ $l        & 0xFF] & "x02x02x02x02x02x02x02x02") |
                    ($shuffleinvip[ $r        & 0xFF] & "x01x01x01x01x01x01x01x01");
                '
;
            }

            
// Creates the inline-crypt function
            
$lambda_functions[$code_hash] = $this->_createInlineCryptFunction(
                array(
                   
'init_crypt'    => $init_crypt,
                   
'init_encrypt'  => $init_encrypt,
                   
'init_decrypt'  => $init_decrypt,
                   
'encrypt_block' => $crypt_block[CRYPT_DES_ENCRYPT],
                   
'decrypt_block' => $crypt_block[CRYPT_DES_DECRYPT]
                )
            );
        }

        
// Set the inline-crypt function as callback in: $this->inline_crypt
        
$this->inline_crypt $lambda_functions[$code_hash];
    }
}
Онлайн: 1
Реклама