search

Home  >  Q&A  >  body text

I want to rewrite this python into PHP, how to break it? Solve

#!/usr/bin/env python
#coding=utf-8
text = 'odd9xifHtMbFIDSY'
pubKey = '010001'
modulus = '00e0b509f6259df8642dbc35662901477df22677ec152b5ff68ace615bb7b725 152b3ab17a876aea8a5aa76d2e417629ec4ee341f56135fccf695280104e0312e cbda92557c93870114af6c9d05c4f7f0c3685b7a46bee255932575cce10b424d8 13cfe4875d3e82047b97ddef52741d546b8e289dc6935b3ece0462db0a22b8e7'
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 = '00e0b509f6259df8642dbc35662901477df22677ec152b5ff68ace615bb7b725 152b3ab17a876aea8a5aa76d2e417629ec4ee341f56135fccf695280104e0312e cbda92557c93870114af6c9d05c4f7f0c3685b7a46bee255932575cce10b424d8 13cfe4875d3e82047b97ddef52741d546b8e289dc6935b3ece0462db0a22b8e7';

$_text = strrev($text);

// Convert hexadecimal to decimal
$biText = intval(bin2hex($_text),16);
$biEx = intval($pubKey, 16);
$biMod = intval($modulus, 16);

// First square, then take the modulo, and then convert to hexadecimal
$biRet = dechex(fmod(pow($biText,$biEx), $biMod));


// Convert decimal to hexadecimal,
while(strlen($biRet) < 256){
    $biRet = '0' . $biRet;
}

echo $biRet;

The maximum value converted by intval is 9223372036854775807. $biText and $biMod are equal, and they are all equal to the maximum value.
$biRet ='NAN', the calculation estimate is out of range.

< /p>

天蓬老师天蓬老师2854 days ago621

reply all(1)I'll reply

  • 滿天的星座

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

    https://github.com/phpmath/bi...
    phpbigint can take a look

    reply
    0
  • Cancelreply