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',計算估計超出了範圍。