2011-12-16 53 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

相關問題