jerry_m Posted March 18, 2012 Share Posted March 18, 2012 Hi there, i have tried without any luck to convert this functions from js to php, can someone help me please? function t1(num) { var hex_chr = "0123456789abcdef"; str = ""; for (j = 0; j <= 3; j++) str += hex_chr.charAt((num >> (j * 8 + 4)) & 0x0F) + hex_chr.charAt((num >> (j * ) & 0x0F); return str; } function t2(str) { nblk = ((str.length + >> 6) + 1; blks = new Array(nblk * 16); for (i = 0; i < nblk * 16; i++) blks[i] = 0; for (i = 0; i < str.length; i++) blks[i >> 2] |= str.charCodeAt(i) << ((i % 4) * ; blks[i >> 2] |= 0x80 << ((i % 4) * ; blks[nblk * 16 - 2] = str.length * 8; return blks; } function t3(x, y) { var lsw = (x & 0xFFFF) + (y & 0xFFFF); var msw = (x >> 16) + (y >> 16) + (lsw >> 16); return (msw << 16) | (lsw & 0xFFFF); } function t4(num, cnt) { return (num << cnt) | (num >>> (32 - cnt)); } function t5(a, b, c, d, x, s, t) { return cmn((b & c) | ((~b) & d), a, b, x, s, t); } Link to comment https://forums.phpfreaks.com/topic/259164-js-to-php/ Share on other sites More sharing options...
trq Posted March 18, 2012 Share Posted March 18, 2012 Help you how? Where exactly are you stuck? Link to comment https://forums.phpfreaks.com/topic/259164-js-to-php/#findComment-1328606 Share on other sites More sharing options...
jerry_m Posted March 18, 2012 Author Share Posted March 18, 2012 Thanks for the reply, well i have partially convert them to php but i have other results than the original js.. function t1($num) { $hex_chr = "0123456789abcdef"; $str = ""; for ($j = 0; $j <= 3; $j++) $str .= $hex_chr[($num >> ($j * 8 + 4)) & 0x0F].$hex_chr[($num >> ($j * ) & 0x0F]; return $str; } function t2($str) { $nblk = ((strlen($str) + >> 6) + 1; $blks = array(); for ($i = 0; $i < $nblk * 16; $i++) $blks[$i] = 0; for ($i = 0; $i < strlen($str); $i++) $blks[$i >> 2] |= $str[$i] << (($i % 4) * ; $blks[$i >> 2] |= 0x80 << (($i % 4) * ; $blks[$nblk * 16 - 2] = strlen($str) * 8; return $blks; } function t3($x, $y) { $lsw = ($x & 0xFFFF) + ($y & 0xFFFF); $msw = ($x >> 16) + ($y >> 16) + ($lsw >> 16); return ($msw << 16) | ($lsw & 0xFFFF); } function t4($num, $cnt) { return ($num << $cnt) | ($num >>> (32 - $cnt)); } function t5($a, $b, $c, $d, $x, $s, $t) { return cmn(($b & $c) | ((~$b) & $d), $a, $b, $x, $s, $t); } Link to comment https://forums.phpfreaks.com/topic/259164-js-to-php/#findComment-1328726 Share on other sites More sharing options...
requinix Posted March 18, 2012 Share Posted March 18, 2012 function t4($num, $cnt) { return ($num >> (32 - $cnt)); } PHP doesn't have a >>> operator. That code should raise a syntax error. Link to comment https://forums.phpfreaks.com/topic/259164-js-to-php/#findComment-1328736 Share on other sites More sharing options...
jerry_m Posted March 18, 2012 Author Share Posted March 18, 2012 Ups, my mistake, it is >> there. Link to comment https://forums.phpfreaks.com/topic/259164-js-to-php/#findComment-1328739 Share on other sites More sharing options...
requinix Posted March 18, 2012 Share Posted March 18, 2012 Can $num ever be negative? That's the only difference I can think of. Link to comment https://forums.phpfreaks.com/topic/259164-js-to-php/#findComment-1328748 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.