2011-12-16 55 views
2

我在使用bcmath时有此错误 -错误 - 调用未定义的方法PEAR_Error的:: int2bin()

Fatal error: Call to undefined method PEAR_Error::int2bin() in login.php on line 23

我试图使用Crypt_RSA和bcmath时一起。这里是我的代码 -

require_once("Crypt/RSA/MathLoader.php"); 
$wrapper_name = “BCMath”; 
$math_obj = &Crypt_RSA_MathLoader::loadWrapper($wrapper_name); 

$a = $math_obj->int2bin("6465130539297209249500692895930266194225707667564124686892613724438982507603215802636578141547940687986170708901198917318074984831856438115515743080726101"); 

回答

1

所以我遇到了类似的问题,当我在几天前在php做一些加密。我需要将一个十进制数字转换为二进制数字。我所做的是将其转换为十六进制,然后将其解压为十六进制编码数据。

<?php 

$a = pack("H*", convBase('6465130539297209249500692895930266194225707667564124686892613724438982507603215802636578141547940687986170708901198917318074984831856438115515743080726101', '', 'ABCDEF')); 

function convBase($numberInput, $fromBaseInput, $toBaseInput) 
{ 
    if ($fromBaseInput==$toBaseInput) return $numberInput; 
    $fromBase = str_split($fromBaseInput,1); 
    $toBase = str_split($toBaseInput,1); 
    $number = str_split($numberInput,1); 
    $fromLen=strlen($fromBaseInput); 
    $toLen=strlen($toBaseInput); 
    $numberLen=strlen($numberInput); 
    $retval=''; 
    if ($toBaseInput == '') 
    { 
     $retval=0; 
     for ($i = 1;$i <= $numberLen; $i++) 
      $retval = bcadd($retval, bcmul(array_search($number[$i-1], $fromBase),bcpow($fromLen,$numberLen-$i))); 
     return $retval; 
    } 
    if ($fromBaseInput != '') 
     $base10=convBase($numberInput, $fromBaseInput, ''); 
    else 
     $base10 = $numberInput; 
    if ($base10<strlen($toBaseInput)) 
     return $toBase[$base10]; 
    while($base10 != '0') 
    { 
     $retval = $toBase[bcmod($base10,$toLen)].$retval; 
     $base10 = bcdiv($base10,$toLen,0); 
    } 
    return $retval; 
} 
?> 
+0

我瘦我可能误解了你的问题... – 2011-12-16 07:58:28

相关问题