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


PHP pack函数代码示例

本文整理汇总了PHP中pack函数的典型用法代码示例。如果您正苦于以下问题:PHP pack函数的具体用法?PHP pack怎么用?PHP pack使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: getRandomBytes

 private function getRandomBytes($count)
 {
     $bytes = '';
     if (function_exists('openssl_random_pseudo_bytes') && strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') {
         // OpenSSL slow on Win
         $bytes = openssl_random_pseudo_bytes($count);
     }
     if ($bytes === '' && @is_readable('/dev/urandom') && ($hRand = @fopen('/dev/urandom', 'rb')) !== FALSE) {
         $bytes = fread($hRand, $count);
         fclose($hRand);
     }
     if (strlen($bytes) < $count) {
         $bytes = '';
         if ($this->randomState === null) {
             $this->randomState = microtime();
             if (function_exists('getmypid')) {
                 $this->randomState .= getmypid();
             }
         }
         for ($i = 0; $i < $count; $i += 16) {
             $this->randomState = md5(microtime() . $this->randomState);
             if (PHP_VERSION >= '5') {
                 $bytes .= md5($this->randomState, true);
             } else {
                 $bytes .= pack('H*', md5($this->randomState));
             }
         }
         $bytes = substr($bytes, 0, $count);
     }
     return $bytes;
 }
开发者ID:vkaran101,项目名称:sase,代码行数:31,代码来源:Bcrypt.php

示例2: convert_uudecode

 function convert_uudecode($string)
 {
     // Sanity check
     if (!is_scalar($string)) {
         user_error('convert_uuencode() expects parameter 1 to be string, ' . gettype($string) . ' given', E_USER_WARNING);
         return false;
     }
     if (strlen($string) < 8) {
         user_error('convert_uuencode() The given parameter is not a valid uuencoded string', E_USER_WARNING);
         return false;
     }
     $decoded = '';
     foreach (explode("\n", $string) as $line) {
         $c = count($bytes = unpack('c*', substr(trim($line), 1)));
         while ($c % 4) {
             $bytes[++$c] = 0;
         }
         foreach (array_chunk($bytes, 4) as $b) {
             $b0 = $b[0] == 0x60 ? 0 : $b[0] - 0x20;
             $b1 = $b[1] == 0x60 ? 0 : $b[1] - 0x20;
             $b2 = $b[2] == 0x60 ? 0 : $b[2] - 0x20;
             $b3 = $b[3] == 0x60 ? 0 : $b[3] - 0x20;
             $b0 <<= 2;
             $b0 |= $b1 >> 4 & 0x3;
             $b1 <<= 4;
             $b1 |= $b2 >> 2 & 0xf;
             $b2 <<= 6;
             $b2 |= $b3 & 0x3f;
             $decoded .= pack('c*', $b0, $b1, $b2);
         }
     }
     return rtrim($decoded, "");
 }
开发者ID:poppen,项目名称:p2,代码行数:33,代码来源:convert_uudecode.php

示例3: hex2bin

 function hex2bin($input, $assume_safe = true)
 {
     if ($assume_safe !== true && !(strlen($input) % 2 === 0 || preg_match('/^[0-9a-f]+$/i', $input))) {
         return '';
     }
     return pack('H*', $input);
 }
开发者ID:Q8HMA,项目名称:BtiTracker-1.5.1,代码行数:7,代码来源:common.php

示例4: encryptMsg

 public function encryptMsg($text)
 {
     $token = $this->account['token'];
     $encodingaeskey = $this->account['encodingaeskey'];
     $appid = $this->account['key'];
     $key = base64_decode($encodingaeskey . '=');
     $text = random(16) . pack("N", strlen($text)) . $text . $appid;
     $size = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC);
     $module = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, '');
     $iv = substr($key, 0, 16);
     $block_size = 32;
     $text_length = strlen($text);
     $amount_to_pad = $block_size - $text_length % $block_size;
     if ($amount_to_pad == 0) {
         $amount_to_pad = $block_size;
     }
     $pad_chr = chr($amount_to_pad);
     $tmp = '';
     for ($index = 0; $index < $amount_to_pad; $index++) {
         $tmp .= $pad_chr;
     }
     $text = $text . $tmp;
     mcrypt_generic_init($module, $key, $iv);
     $encrypted = mcrypt_generic($module, $text);
     mcrypt_generic_deinit($module);
     mcrypt_module_close($module);
     $encrypt_msg = base64_encode($encrypted);
     $signature = $this->buildSignature($encrypt_msg);
     return array($signature, $encrypt_msg);
 }
开发者ID:7demo,项目名称:we7,代码行数:30,代码来源:weixin.account.class.php

示例5: storeDocuments

 public function storeDocuments($name, array $documents = null)
 {
     if ($name === null || $documents === null || trim($name) == '') {
         return false;
     }
     if (!is_string($name) || !is_array($documents)) {
         return false;
     }
     foreach ($documents as $doc) {
         if (!$this->validateDocument($doc)) {
             return false;
         }
     }
     $fp = fopen($this->_getFilePathName($name), 'w');
     foreach ($documents as $doc) {
         $bindata1 = pack('i', intval($doc[0]));
         $bindata2 = pack('i', intval($doc[1]));
         $bindata3 = pack('i', intval($doc[2]));
         fwrite($fp, $bindata1);
         fwrite($fp, $bindata2);
         fwrite($fp, $bindata3);
     }
     fclose($fp);
     return true;
 }
开发者ID:thegeekajay,项目名称:search-engine,代码行数:25,代码来源:multifolderindex.class.php

示例6: appendHeader

 protected function appendHeader($request, $id = null)
 {
     if ($id === null) {
         $id = $this->getId();
     }
     return pack("NN", strlen($request) | 0x80000000, $id) . $request;
 }
开发者ID:wanggeopens,项目名称:own-libs,代码行数:7,代码来源:FullDuplexTransporter.php

示例7: chapchallengeresponse

function chapchallengeresponse($challenge, $password)
{
    // Generates a response for a challenge response CHAP Auth
    $hexChallenge = pack("H32", $challenge);
    $response = md5("" . $password . $hexChallenge);
    return $response;
}
开发者ID:KuberKode,项目名称:grase-www-portal,代码行数:7,代码来源:automacusers.php

示例8: convertip_tiny

 public function convertip_tiny($ip, $ipdatafile)
 {
     static $fp = NULL, $offset = array(), $index = NULL;
     $ipdot = explode('.', $ip);
     $ip = pack('N', ip2long($ip));
     $ipdot[0] = (int) $ipdot[0];
     $ipdot[1] = (int) $ipdot[1];
     if ($fp === NULL && ($fp = @fopen($ipdatafile, 'rb'))) {
         $offset = @unpack('Nlen', @fread($fp, 4));
         $index = @fread($fp, $offset['len'] - 4);
     } elseif ($fp == FALSE) {
         return '- Invalid IP data file';
     }
     $length = $offset['len'] - 1028;
     $start = @unpack('Vlen', $index[$ipdot[0] * 4] . $index[$ipdot[0] * 4 + 1] . $index[$ipdot[0] * 4 + 2] . $index[$ipdot[0] * 4 + 3]);
     for ($start = $start['len'] * 8 + 1024; $start < $length; $start += 8) {
         if ($index[$start] . $index[$start + 1] . $index[$start + 2] . $index[$start + 3] >= $ip) {
             $index_offset = @unpack('Vlen', $index[$start + 4] . $index[$start + 5] . $index[$start + 6] . "");
             $index_length = @unpack('Clen', $index[$start + 7]);
             break;
         }
     }
     @fseek($fp, $offset['len'] + $index_offset['len'] - 1024);
     if ($index_length['len']) {
         return '- ' . @fread($fp, $index_length['len']);
     } else {
         return '- Unknown';
     }
 }
开发者ID:a195474368,项目名称:ejiawang,代码行数:29,代码来源:location.mdl.php

示例9: chr

 /**
  * Returns a specific character in UTF-8.
  * @param  int     codepoint
  * @return string
  */
 public static function chr($code)
 {
     if (func_num_args() > 1 && strcasecmp(func_get_arg(1), 'UTF-8')) {
         trigger_error(__METHOD__ . ' supports only UTF-8 encoding.', E_USER_DEPRECATED);
     }
     return iconv('UTF-32BE', 'UTF-8//IGNORE', pack('N', $code));
 }
开发者ID:rostenkowski,项目名称:nette,代码行数:12,代码来源:Strings.php

示例10: encrypt

 /**
  * The symmetric encryption function
  *
  * @param string $pwd Key to encrypt with (can be binary of hex)
  * @param string $data Content to be encrypted
  * @param bool $ispwdHex Key passed is in hexadecimal or not
  * @access public
  * @return string
  */
 function encrypt($pwd, $data, $ispwdHex = 0)
 {
     if ($ispwdHex) {
         $pwd = @pack('H*', $pwd);
     }
     // valid input, please!
     $key[] = '';
     $box[] = '';
     $cipher = '';
     $pwd_length = strlen($pwd);
     $data_length = strlen($data);
     for ($i = 0; $i < 256; $i++) {
         $key[$i] = ord($pwd[$i % $pwd_length]);
         $box[$i] = $i;
     }
     for ($j = $i = 0; $i < 256; $i++) {
         $j = ($j + $box[$i] + $key[$i]) % 256;
         $tmp = $box[$i];
         $box[$i] = $box[$j];
         $box[$j] = $tmp;
     }
     for ($a = $j = $i = 0; $i < $data_length; $i++) {
         $a = ($a + 1) % 256;
         $j = ($j + $box[$a]) % 256;
         $tmp = $box[$a];
         $box[$a] = $box[$j];
         $box[$j] = $tmp;
         $k = $box[($box[$a] + $box[$j]) % 256];
         $cipher .= chr(ord($data[$i]) ^ $k);
     }
     return $cipher;
 }
开发者ID:alesconti,项目名称:FF_2015,代码行数:41,代码来源:rc4.php

示例11: pbkdf2

function pbkdf2($algorithm, $password, $salt, $count, $key_length, $raw_output = false)
{
    $algorithm = strtolower($algorithm);
    if (!in_array($algorithm, hash_algos(), true)) {
        die('PBKDF2 ERROR: Invalid hash algorithm.');
    }
    if ($count <= 0 || $key_length <= 0) {
        die('PBKDF2 ERROR: Invalid parameters.');
    }
    $hash_length = strlen(hash($algorithm, "", true));
    $block_count = ceil($key_length / $hash_length);
    $output = "";
    for ($i = 1; $i <= $block_count; $i++) {
        // $i encoded as 4 bytes, big endian.
        $last = $salt . pack("N", $i);
        // first iteration
        $last = $xorsum = hash_hmac($algorithm, $last, $password, true);
        // perform the other $count - 1 iterations
        for ($j = 1; $j < $count; $j++) {
            $xorsum ^= $last = hash_hmac($algorithm, $last, $password, true);
        }
        $output .= $xorsum;
    }
    if ($raw_output) {
        return substr($output, 0, $key_length);
    } else {
        return bin2hex(substr($output, 0, $key_length));
    }
}
开发者ID:Ayeblinken,项目名称:potonka,代码行数:29,代码来源:password_helper.php

示例12: parse

 public function parse()
 {
     $matches = array();
     if ($this->softmode) {
         $res = preg_match(self::PATTERN_SOFTMODE, trim($this->fileContent), $matches);
     } else {
         $res = preg_match(self::PATTERN, $this->fileContent, $matches);
     }
     if ($res === false || $res === 0) {
         throw new \Exception($this->filename . ' is not a proper .srt file.');
     }
     $this->setLineEnding($matches[1]);
     $bom = pack('CCC', 0xef, 0xbb, 0xbf);
     $matches = explode($this->lineEnding . $this->lineEnding, trim($matches[0], $bom . $this->lineEnding));
     $subtitleOrder = 1;
     $subtitleTime = '';
     foreach ($matches as $match) {
         $subtitle = explode($this->lineEnding, $match, 3);
         $timeline = explode(' --> ', $subtitle[1]);
         $subtitleTimeStart = $timeline[0];
         $subtitleTimeEnd = $timeline[1];
         if (!$this->softmode && ($subtitle[0] != $subtitleOrder++ || !$this->validateTimelines($subtitleTime, $subtitleTimeStart, true) || !$this->validateTimelines($subtitleTimeStart, $subtitleTimeEnd))) {
             throw new \Exception($this->filename . ' is not a proper .srt file.');
         }
         $subtitleTime = $subtitleTimeEnd;
         $cue = new SubripCue($timeline[0], $timeline[1], isset($subtitle[2]) ? $subtitle[2] : '');
         $cue->setLineEnding($this->lineEnding);
         $this->addCue($cue);
     }
     return $this;
 }
开发者ID:sovic,项目名称:captioning,代码行数:31,代码来源:SubripFile.php

示例13: hexstr

function hexstr($hexstr)
{
    $hexstr = str_replace(' ', '', $hexstr);
    $hexstr = str_replace('\\x', '', $hexstr);
    $retstr = pack('H*', $hexstr);
    return $retstr;
}
开发者ID:rgfretes,项目名称:hotel-center-vcp,代码行数:7,代码来源:sendmail.php

示例14: getData

 /**
  * Generate the WSBOOL biff record
  * @param Worksheet $sheet
  *
  * @return string
  */
 public function getData(Worksheet $sheet)
 {
     $grbit = 0x0;
     // Set the option flags
     $grbit |= 0x1;
     // Auto page breaks visible
     if ($sheet->getOutlineStyle()) {
         $grbit |= 0x20;
         // Auto outline styles
     }
     if ($sheet->getOutlineBelow()) {
         $grbit |= 0x40;
         // Outline summary below
     }
     if ($sheet->getOutlineRight()) {
         $grbit |= 0x80;
         // Outline summary right
     }
     if ($sheet->getPrintSetup()->isFitPage()) {
         $grbit |= 0x100;
         // Page setup fit to page
     }
     if ($sheet->isOutlineOn()) {
         $grbit |= 0x400;
         // Outline symbols displayed
     }
     $data = pack("v", $grbit);
     return $this->getFullRecord($data);
 }
开发者ID:maxakawizard,项目名称:xls-writer,代码行数:35,代码来源:WsBool.php

示例15: removeBom

 /**
  * Remove the byte order mark from a string if applicable
  *
  * @param string $string
  * @return string
  */
 public static function removeBom($string)
 {
     if (substr($string, 0, 3) == pack('CCC', 0xef, 0xbb, 0xbf)) {
         $string = substr($string, 3);
     }
     return $string;
 }
开发者ID:oat-sa,项目名称:jig,代码行数:13,代码来源:StringUtils.php


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