Maison  >  Questions et réponses  >  le corps du texte

这段 python 想改写成 PHP,怎么破?求解

#!/usr/bin/env python
# coding=utf-8
text = 'odd9xifHtMbFIDSY'
pubKey = '010001'
modulus = '00e0b509f6259df8642dbc35662901477df22677ec152b5ff68ace615bb7b725152b3ab17a876aea8a5aa76d2e417629ec4ee341f56135fccf695280104e0312ecbda92557c93870114af6c9d05c4f7f0c3685b7a46bee255932575cce10b424d813cfe4875d3e82047b97ddef52741d546b8e289dc6935b3ece0462db0a22b8e7'
text = text[::-1]
rs = int(text.encode('hex'), 16)**int(pubKey, 16)%int(modulus, 16)
r = format(rs, 'x').zfill(256)
print r
$text = 'odd9xifHtMbFIDSY';
$pubKey = '010001';
$modulus = '00e0b509f6259df8642dbc35662901477df22677ec152b5ff68ace615bb7b725152b3ab17a876aea8a5aa76d2e417629ec4ee341f56135fccf695280104e0312ecbda92557c93870114af6c9d05c4f7f0c3685b7a46bee255932575cce10b424d813cfe4875d3e82047b97ddef52741d546b8e289dc6935b3ece0462db0a22b8e7';

$_text = strrev($text);

// 十六进制转十进制
$biText = intval(bin2hex($_text),16);
$biEx = intval($pubKey, 16);
$biMod = intval($modulus, 16);

// 先平方,后取模, 再转十六进制
$biRet = dechex(fmod(pow($biText,$biEx),  $biMod));


// 十进制转十六进制,
while(strlen($biRet) < 256){
    $biRet = '0' . $biRet;
}

echo $biRet;

intval转换的最大值是9223372036854775807,$biText $biMod 相等了,都等于最大值。
$biRet ='NAN',计算估计超出了范围。

天蓬老师天蓬老师2736 Il y a quelques jours531

répondre à tous(1)je répondrai

  • 滿天的星座

    滿天的星座2017-05-16 13:03:43

    https://github.com/phpmath/bi...
    phpbigint peut y jeter un oeil

    répondre
    0
  • Annulerrépondre