当前位置: 首页>>代码示例>>PHP>>正文


PHP Crypt_DES::get_lambda_functions方法代码示例

本文整理汇总了PHP中Crypt_DES::get_lambda_functions方法的典型用法代码示例。如果您正苦于以下问题:PHP Crypt_DES::get_lambda_functions方法的具体用法?PHP Crypt_DES::get_lambda_functions怎么用?PHP Crypt_DES::get_lambda_functions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Crypt_DES的用法示例。


在下文中一共展示了Crypt_DES::get_lambda_functions方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: inline_crypt_setup

    /**
     * Creates performance-optimized function for de/encrypt(), storing it in $this->inline_crypt
     *
     * @param optional Integer $des_rounds (1 = DES[default], 3 = TribleDES)
     * @access private
     */
    function inline_crypt_setup($des_rounds = 1)
    {
        $lambda_functions =& Crypt_DES::get_lambda_functions();
        $block_size = 8;
        $mode = $this->mode;
        $code_hash = "{$mode},{$des_rounds}";
        if (!isset($lambda_functions[$code_hash])) {
            // Generating encrypt code:
            $ki = -1;
            $init_cryptBlock = '
                $shuffle  = $self->shuffle;
                $invipmap = $self->invipmap;
                $ipmap = $self->ipmap;
                $sbox1 = $self->sbox1;
                $sbox2 = $self->sbox2;
                $sbox3 = $self->sbox3;
                $sbox4 = $self->sbox4;
                $sbox5 = $self->sbox5;
                $sbox6 = $self->sbox6;
                $sbox7 = $self->sbox7;
                $sbox8 = $self->sbox8;
            ';
            $_cryptBlock = '$in = unpack("N*", $in);' . "\n";
            // Do the initial IP permutation.
            $_cryptBlock .= '
                $l  = $in[1];
                $r  = $in[2];
                $in = unpack("N*",
                    ($shuffle[$ipmap[ $r        & 0xFF]] & "\\x80\\x80\\x80\\x80\\x80\\x80\\x80\\x80") |
                    ($shuffle[$ipmap[($r >>  8) & 0xFF]] & "\\x40\\x40\\x40\\x40\\x40\\x40\\x40\\x40") |
                    ($shuffle[$ipmap[($r >> 16) & 0xFF]] & "\\x20\\x20\\x20\\x20\\x20\\x20\\x20\\x20") |
                    ($shuffle[$ipmap[($r >> 24) & 0xFF]] & "\\x10\\x10\\x10\\x10\\x10\\x10\\x10\\x10") |
                    ($shuffle[$ipmap[ $l        & 0xFF]] & "\\x08\\x08\\x08\\x08\\x08\\x08\\x08\\x08") |
                    ($shuffle[$ipmap[($l >>  8) & 0xFF]] & "\\x04\\x04\\x04\\x04\\x04\\x04\\x04\\x04") |
                    ($shuffle[$ipmap[($l >> 16) & 0xFF]] & "\\x02\\x02\\x02\\x02\\x02\\x02\\x02\\x02") |
                    ($shuffle[$ipmap[($l >> 24) & 0xFF]] & "\\x01\\x01\\x01\\x01\\x01\\x01\\x01\\x01")
                );

                ' . '' . '
                $l = $in[1];
                $r = $in[2];
            ';
            $l = 'l';
            $r = 'r';
            for ($des_round = 0; $des_round < $des_rounds; ++$des_round) {
                // Perform the 16 steps.
                // 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.
                for ($i = 0; $i < 8; ++$i) {
                    $_cryptBlock .= '
                        $b1 = (($' . $r . ' >>  3) & 0x1FFFFFFF)  ^ ($' . $r . ' << 29) ^ $k_' . ++$ki . ';
                        $b2 = (($' . $r . ' >> 31) & 0x00000001)  ^ ($' . $r . ' <<  1) ^ $k_' . ++$ki . ';
                        $' . $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 . ';

                        $b1 = (($' . $l . ' >>  3) & 0x1FFFFFFF)  ^ ($' . $l . ' << 29) ^ $k_' . ++$ki . ';
                        $b2 = (($' . $l . ' >> 31) & 0x00000001)  ^ ($' . $l . ' <<  1) ^ $k_' . ++$ki . ';
                        $' . $r . '  = $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] ^ $' . $r . ';
                    ';
                }
                // Last step should not permute L & R.
                $t = $l;
                $l = $r;
                $r = $t;
            }
            // Perform the inverse IP permutation.
            $_cryptBlock .= '$in = (
                    ($shuffle[$invipmap[($' . $r . ' >> 24) & 0xFF]] & "\\x80\\x80\\x80\\x80\\x80\\x80\\x80\\x80") |
                    ($shuffle[$invipmap[($' . $l . ' >> 24) & 0xFF]] & "\\x40\\x40\\x40\\x40\\x40\\x40\\x40\\x40") |
                    ($shuffle[$invipmap[($' . $r . ' >> 16) & 0xFF]] & "\\x20\\x20\\x20\\x20\\x20\\x20\\x20\\x20") |
                    ($shuffle[$invipmap[($' . $l . ' >> 16) & 0xFF]] & "\\x10\\x10\\x10\\x10\\x10\\x10\\x10\\x10") |
                    ($shuffle[$invipmap[($' . $r . ' >>  8) & 0xFF]] & "\\x08\\x08\\x08\\x08\\x08\\x08\\x08\\x08") |
                    ($shuffle[$invipmap[($' . $l . ' >>  8) & 0xFF]] & "\\x04\\x04\\x04\\x04\\x04\\x04\\x04\\x04") |
                    ($shuffle[$invipmap[ $' . $r . '        & 0xFF]] & "\\x02\\x02\\x02\\x02\\x02\\x02\\x02\\x02") |
                    ($shuffle[$invipmap[ $' . $l . '        & 0xFF]] & "\\x01\\x01\\x01\\x01\\x01\\x01\\x01\\x01")
                );
            ';
            // Generating mode of operation code:
            switch ($mode) {
                case CRYPT_DES_MODE_ECB:
                    $encrypt = $init_cryptBlock . '
                        extract($self->keys[CRYPT_DES_ENCRYPT_1DIM],  EXTR_PREFIX_ALL, "k");
                        $ciphertext = "";
                        $plaintext_len = strlen($text);

                        for ($i = 0; $i < $plaintext_len; $i+= ' . $block_size . ') {
                            $in = substr($text, $i, ' . $block_size . ');
                            ' . $_cryptBlock . '
//.........这里部分代码省略.........
开发者ID:sspaeti,项目名称:ImpressPages,代码行数:101,代码来源:DES.php

示例2: inline_crypt_setup

    function inline_crypt_setup($des_rounds = 1)
    {
        $lambda_functions =& Crypt_DES::get_lambda_functions();
        $block_size = 8;
        $mode = $this->mode;

        $code_hash = "$mode,$des_rounds";

        if (!isset($lambda_functions[$code_hash])) {
                        $ki = -1;
            $init_cryptBlock = '
                $shuffle  = $self->shuffle;
                $invipmap = $self->invipmap;
                $ipmap = $self->ipmap;
                $sbox1 = $self->sbox1;
                $sbox2 = $self->sbox2;
                $sbox3 = $self->sbox3;
                $sbox4 = $self->sbox4;
                $sbox5 = $self->sbox5;
                $sbox6 = $self->sbox6;
                $sbox7 = $self->sbox7;
                $sbox8 = $self->sbox8;
            ';

            $_cryptBlock = '$in = unpack("N*", $in);'."\n";
                        $_cryptBlock .= '
                $l  = $in[1];
                $r  = $in[2];
                $in = unpack("N*",
                    ($shuffle[$ipmap[ $r        & 0xFF]] & "\x80\x80\x80\x80\x80\x80\x80\x80") |
                    ($shuffle[$ipmap[($r >>  8) & 0xFF]] & "\x40\x40\x40\x40\x40\x40\x40\x40") |
                    ($shuffle[$ipmap[($r >> 16) & 0xFF]] & "\x20\x20\x20\x20\x20\x20\x20\x20") |
                    ($shuffle[$ipmap[($r >> 24) & 0xFF]] & "\x10\x10\x10\x10\x10\x10\x10\x10") |
                    ($shuffle[$ipmap[ $l        & 0xFF]] & "\x08\x08\x08\x08\x08\x08\x08\x08") |
                    ($shuffle[$ipmap[($l >>  8) & 0xFF]] & "\x04\x04\x04\x04\x04\x04\x04\x04") |
                    ($shuffle[$ipmap[($l >> 16) & 0xFF]] & "\x02\x02\x02\x02\x02\x02\x02\x02") |
                    ($shuffle[$ipmap[($l >> 24) & 0xFF]] & "\x01\x01\x01\x01\x01\x01\x01\x01")
                );

                '.''  .'
                $l = $in[1];
                $r = $in[2];
            ';

            $l = 'l';
            $r = 'r';
            for ($des_round = 0; $des_round < $des_rounds; ++$des_round) {
                                                                                for ($i = 0; $i < 8; ++$i) {
                    $_cryptBlock .= '
                        $b1 = (($' . $r . ' >>  3) & 0x1FFFFFFF)  ^ ($' . $r . ' << 29) ^ $k_'.(++$ki).';
                        $b2 = (($' . $r . ' >> 31) & 0x00000001)  ^ ($' . $r . ' <<  1) ^ $k_'.(++$ki).';
                        $' . $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 . ';

                        $b1 = (($' . $l . ' >>  3) & 0x1FFFFFFF)  ^ ($' . $l . ' << 29) ^ $k_'.(++$ki).';
                        $b2 = (($' . $l . ' >> 31) & 0x00000001)  ^ ($' . $l . ' <<  1) ^ $k_'.(++$ki).';
                        $' . $r . '  = $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] ^ $' . $r . ';
                    ';
                }

                                $t = $l;
                $l = $r;
                $r = $t;
            }

                        $_cryptBlock .= '$in = (
                    ($shuffle[$invipmap[($' . $r . ' >> 24) & 0xFF]] & "\x80\x80\x80\x80\x80\x80\x80\x80") |
                    ($shuffle[$invipmap[($' . $l . ' >> 24) & 0xFF]] & "\x40\x40\x40\x40\x40\x40\x40\x40") |
                    ($shuffle[$invipmap[($' . $r . ' >> 16) & 0xFF]] & "\x20\x20\x20\x20\x20\x20\x20\x20") |
                    ($shuffle[$invipmap[($' . $l . ' >> 16) & 0xFF]] & "\x10\x10\x10\x10\x10\x10\x10\x10") |
                    ($shuffle[$invipmap[($' . $r . ' >>  8) & 0xFF]] & "\x08\x08\x08\x08\x08\x08\x08\x08") |
                    ($shuffle[$invipmap[($' . $l . ' >>  8) & 0xFF]] & "\x04\x04\x04\x04\x04\x04\x04\x04") |
                    ($shuffle[$invipmap[ $' . $r . '        & 0xFF]] & "\x02\x02\x02\x02\x02\x02\x02\x02") |
                    ($shuffle[$invipmap[ $' . $l . '        & 0xFF]] & "\x01\x01\x01\x01\x01\x01\x01\x01")
                );
            ';

                        switch ($mode) {
                case CRYPT_DES_MODE_ECB:
                    $encrypt = $init_cryptBlock . '
                        extract($self->keys[CRYPT_DES_ENCRYPT_1DIM],  EXTR_PREFIX_ALL, "k");
                        $ciphertext = "";
                        $plaintext_len = strlen($text);

                        for ($i = 0; $i < $plaintext_len; $i+= '.$block_size.') {
                            $in = substr($text, $i, '.$block_size.');
                            '.$_cryptBlock.'
                            $ciphertext.= $in;
                        }

                        return $ciphertext;
                        ';

                    $decrypt = $init_cryptBlock . '
                        extract($self->keys[CRYPT_DES_DECRYPT_1DIM],  EXTR_PREFIX_ALL, "k");
//.........这里部分代码省略.........
开发者ID:pf5512,项目名称:phpstudy,代码行数:101,代码来源:Crypt_DES.php


注:本文中的Crypt_DES::get_lambda_functions方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。