Rumah > Soal Jawab > teks badan
python 代码
#!/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
php 自己尝试写的,但是失败了,麻烦帮忙分析下具体原因。
$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',计算估计超出了范围。