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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.