Jump to content

js to php


jerry_m

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.