Jump to content

PHP2AutoIT


TranZ
 Share

Recommended Posts

Hello!

Please help me translate this functions to AutoIT code.

It is very important for my work and sometimes I working on PC's where no possible install PHP interpreter... :)

I was try translate all myself but I'm not understand how translate for example this:

"~$z", "$a >> $b", "$c ^= (ZeroFill($b, 13))"

Partial PHP-code(with my comments):

<?php

// Global Const $CHECK_WORD
define('CHECK_WORD', 0xE6359A60);
//>>>-Func-ZeroFill->>>
function ZeroFill($a, $b)
{
    $z = hexdec(80000000);

    if ($z & $a)
    {
        $a = ($a >> 1);
        $a &= (~$z);
        $a = 0x40000000;
        $a = ($a >> ($b - 1));
    }
    else
    {
        $a = ($a >> $b);
    }
    return $a;
}
//>>>-Func-Mix->>>
function Mix($a, $b, $c)
{
    $a -= $b;
    $a -= $c;
    $a ^= (ZeroFill($c, 13));

    $b -= $c;
    $b -= $a;
    $b ^= ($a << 8);

    $c -= $a;
    $c -= $b;
    $c ^= (ZeroFill($b, 13));

    $a -= $b;
    $a -= $c;
    $a ^= (ZeroFill($c, 12));

    $b -= $c;
    $b -= $a;
    $b ^= ($a << 16);

    $c -= $a;
    $c -= $b;
    $c ^= (ZeroFill($b, 5));

    $a -= $b;
    $a -= $c;
    $a ^= (ZeroFill($c, 3));

    $b -= $c;
    $b -= $a;
    $b ^= ($a << 10);

    $c -= $a;
    $c -= $b;
    $c ^= (ZeroFill($b, 15));

    return array($a, $b, $c);
}
//>>>-Func-CheckSum->>>
function CheckSum($string, $length = null, $init = CHECK_WORD)
{
    //I think that this If statement really needed only for check value from form
    if (is_null($length))
    {
        $length = sizeof($string);
    }

    $a = $b = 0x9E3779B9;
    $c = $init;
    $k = 0;
    $len = $length;

    while($len >= 12)
    {
        $a += ($string[$k + 0] + ($string[$k + 1] << 8) + ($string[$k + 2] << 16) + ($string[$k + 3] << 24));
        $b += ($string[$k + 4] + ($string[$k + 5] << 8) + ($string[$k + 6] << 16) + ($string[$k + 7] << 24));
        $c += ($string[$k + 8] + ($string[$k + 9] << 8) + ($string[$k + 10] << 16) + ($string[$k + 11] << 24));
        $mix = mix($a, $b, $c);
        $a = $mix[0];
        $b = $mix[1];
        $c = $mix[2];
        $k += 12;
        $len -= 12;
    }

    $c += $length;

    switch ($len)
    {
        case 11: $c += ($string[$k + 10] << 24);
        case 10: $c += ($string[$k + 9] << 16);
        case 9 : $c += ($string[$k + 8] << 8);
        //>>> First byte $c is reserved for $length value
        case 8 : $b += ($string[$k + 7] << 24);
        case 7 : $b += ($string[$k + 6] << 16);
        case 6 : $b += ($string[$k + 5] << 8);
        case 5 : $b += ($string[$k + 4]);
        case 4 : $a += ($string[$k + 3] << 24);
        case 3 : $a += ($string[$k + 2] << 16);
        case 2 : $a += ($string[$k + 1] << 8);
        case 1 : $a += ($string[$k + 0]);
    }

    $mix = mix($a, $b, $c);

    return $mix[2];
}

// [...]

?>

P.S.: Script not written by me, but it's open-source.

Link to comment
Share on other sites

Hello!

Please help me translate this functions to AutoIT code.

It is very important for my work and sometimes I working on PC's where no possible install PHP interpreter... :)

I was try translate all myself but I'm not understand how translate for example this:

"~$z", "$a >> $b", "$c ^= (ZeroFill($b, 13))"

Partial PHP-code(with my comments):

<?php

// Global Const $CHECK_WORD
define('CHECK_WORD', 0xE6359A60);
//>>>-Func-ZeroFill->>>
function ZeroFill($a, $b)
{
    $z = hexdec(80000000);

    if ($z & $a)
    {
        $a = ($a >> 1);
        $a &= (~$z);
        $a = 0x40000000;
        $a = ($a >> ($b - 1));
    }
    else
    {
        $a = ($a >> $b);
    }
    return $a;
}
//>>>-Func-Mix->>>
function Mix($a, $b, $c)
{
    $a -= $b;
    $a -= $c;
    $a ^= (ZeroFill($c, 13));

    $b -= $c;
    $b -= $a;
    $b ^= ($a << 8);

    $c -= $a;
    $c -= $b;
    $c ^= (ZeroFill($b, 13));

    $a -= $b;
    $a -= $c;
    $a ^= (ZeroFill($c, 12));

    $b -= $c;
    $b -= $a;
    $b ^= ($a << 16);

    $c -= $a;
    $c -= $b;
    $c ^= (ZeroFill($b, 5));

    $a -= $b;
    $a -= $c;
    $a ^= (ZeroFill($c, 3));

    $b -= $c;
    $b -= $a;
    $b ^= ($a << 10);

    $c -= $a;
    $c -= $b;
    $c ^= (ZeroFill($b, 15));

    return array($a, $b, $c);
}
//>>>-Func-CheckSum->>>
function CheckSum($string, $length = null, $init = CHECK_WORD)
{
    //I think that this If statement really needed only for check value from form
    if (is_null($length))
    {
        $length = sizeof($string);
    }

    $a = $b = 0x9E3779B9;
    $c = $init;
    $k = 0;
    $len = $length;

    while($len >= 12)
    {
        $a += ($string[$k + 0] + ($string[$k + 1] << 8) + ($string[$k + 2] << 16) + ($string[$k + 3] << 24));
        $b += ($string[$k + 4] + ($string[$k + 5] << 8) + ($string[$k + 6] << 16) + ($string[$k + 7] << 24));
        $c += ($string[$k + 8] + ($string[$k + 9] << 8) + ($string[$k + 10] << 16) + ($string[$k + 11] << 24));
        $mix = mix($a, $b, $c);
        $a = $mix[0];
        $b = $mix[1];
        $c = $mix[2];
        $k += 12;
        $len -= 12;
    }

    $c += $length;

    switch ($len)
    {
        case 11: $c += ($string[$k + 10] << 24);
        case 10: $c += ($string[$k + 9] << 16);
        case 9 : $c += ($string[$k + 8] << 8);
        //>>> First byte $c is reserved for $length value
        case 8 : $b += ($string[$k + 7] << 24);
        case 7 : $b += ($string[$k + 6] << 16);
        case 6 : $b += ($string[$k + 5] << 8);
        case 5 : $b += ($string[$k + 4]);
        case 4 : $a += ($string[$k + 3] << 24);
        case 3 : $a += ($string[$k + 2] << 16);
        case 2 : $a += ($string[$k + 1] << 8);
        case 1 : $a += ($string[$k + 0]);
    }

    $mix = mix($a, $b, $c);

    return $mix[2];
}

// [...]

?>

P.S.: Script not written by me, but it's open-source.

The "~$z" is bit-wise NOT $z (compliment).

The "$a >> $b" is bit-wise shift $a right $b times (sign fill).

The "$c ^= (ZeroFill($b, 13))" part sets $c to the XOR of $c and the results of the call to ZeroFill($b, 13).

I don't do PHP. Figured that out with 90sec of Google for "PHP Operators" and "PHP bitwise operators".

You can too...

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Hello!

Please help me translate this functions to AutoIT code.

It is very important for my work and sometimes I working on PC's where no possible install PHP interpreter... :)

I was try translate all myself but I'm not understand how translate for example this:

"~$z", "$a >> $b", "$c ^= (ZeroFill($b, 13))"

Partial PHP-code(with my comments):

<?php

// Global Const $CHECK_WORD
define('CHECK_WORD', 0xE6359A60);
//>>>-Func-ZeroFill->>>
function ZeroFill($a, $b)
{
    $z = hexdec(80000000);

    if ($z & $a)
    {
        $a = ($a >> 1);
        $a &= (~$z);
        $a = 0x40000000;
        $a = ($a >> ($b - 1));
    }
    else
    {
        $a = ($a >> $b);
    }
    return $a;
}
//>>>-Func-Mix->>>
function Mix($a, $b, $c)
{
    $a -= $b;
    $a -= $c;
    $a ^= (ZeroFill($c, 13));

    $b -= $c;
    $b -= $a;
    $b ^= ($a << 8);

    $c -= $a;
    $c -= $b;
    $c ^= (ZeroFill($b, 13));

    $a -= $b;
    $a -= $c;
    $a ^= (ZeroFill($c, 12));

    $b -= $c;
    $b -= $a;
    $b ^= ($a << 16);

    $c -= $a;
    $c -= $b;
    $c ^= (ZeroFill($b, 5));

    $a -= $b;
    $a -= $c;
    $a ^= (ZeroFill($c, 3));

    $b -= $c;
    $b -= $a;
    $b ^= ($a << 10);

    $c -= $a;
    $c -= $b;
    $c ^= (ZeroFill($b, 15));

    return array($a, $b, $c);
}
//>>>-Func-CheckSum->>>
function CheckSum($string, $length = null, $init = CHECK_WORD)
{
    //I think that this If statement really needed only for check value from form
    if (is_null($length))
    {
        $length = sizeof($string);
    }

    $a = $b = 0x9E3779B9;
    $c = $init;
    $k = 0;
    $len = $length;

    while($len >= 12)
    {
        $a += ($string[$k + 0] + ($string[$k + 1] << 8) + ($string[$k + 2] << 16) + ($string[$k + 3] << 24));
        $b += ($string[$k + 4] + ($string[$k + 5] << 8) + ($string[$k + 6] << 16) + ($string[$k + 7] << 24));
        $c += ($string[$k + 8] + ($string[$k + 9] << 8) + ($string[$k + 10] << 16) + ($string[$k + 11] << 24));
        $mix = mix($a, $b, $c);
        $a = $mix[0];
        $b = $mix[1];
        $c = $mix[2];
        $k += 12;
        $len -= 12;
    }

    $c += $length;

    switch ($len)
    {
        case 11: $c += ($string[$k + 10] << 24);
        case 10: $c += ($string[$k + 9] << 16);
        case 9 : $c += ($string[$k + 8] << 8);
        //>>> First byte $c is reserved for $length value
        case 8 : $b += ($string[$k + 7] << 24);
        case 7 : $b += ($string[$k + 6] << 16);
        case 6 : $b += ($string[$k + 5] << 8);
        case 5 : $b += ($string[$k + 4]);
        case 4 : $a += ($string[$k + 3] << 24);
        case 3 : $a += ($string[$k + 2] << 16);
        case 2 : $a += ($string[$k + 1] << 8);
        case 1 : $a += ($string[$k + 0]);
    }

    $mix = mix($a, $b, $c);

    return $mix[2];
}

// [...]

?>

P.S.: Script not written by me, but it's open-source.

CheckSum

http://oman922.110mb.com/autoit.php

$R = CheckSum("123456789123456789123456")
MsgBox(0,"",$R)
Func ZeroFill($a, $b)

    $z = (Dec(80000000));

    if BitAND($z , $a) Then

        $a = BitShift($a , 1);
        $a = BitAND($a ,BitNOT($z));
        $a = 0x40000000;
        $a = BitShift($a , ($b - 1));

    else

        $a = BitShift($a , $b);

    EndIf
    return $a;

EndFunc


Func CheckSum($string, $length = 0, $init = 0xE6359A60) ;$CHECK_WORD = 0xE6359A60

    ;//I think that this If statement really needed only for check value from form
    if ($length = 0) Then
        $length = 1; sizeof string Only 1 / 1 rows
    EndIf
    $string = StringSplit($string,"")
    Dim $OutArray[$string[0]]
    For $i = 1 To $string[0] Step 1
    $OutArray[$i - 1] = ($string[$i])
    Next
    $string = $OutArray

    $b = 0x9E3779B9
    $a = $b;
    $c = $init;
    $k = 0;
    $len = $length;

    while($len >= 12)
        $a += ($string[$k + 0] + BitShift($string[$k + 1] , -8) + BitShift($string[$k + 2] , -16) _
        + BitShift($string[$k + 3] , -24));
        $b += ($string[$k + 4] + BitShift($string[$k + 5] , -8) + BitShift($string[$k + 6] , -16) _
        + BitShift($string[$k + 7] , -24));
        $c += ($string[$k + 8] + BitShift($string[$k + 9] , -8) + BitShift($string[$k + 10] , -16) _
        + BitShift($string[$k + 11] , -24));
        $mix = mix($a, $b, $c);
        $a = $mix[0];
        $b = $mix[1];
        $c = $mix[2];
        $k += 12;
        $len -= 12;
    WEnd

    $c += $length;

    switch ($len)
    case 11
        $c += BitShift($string[$k + 10] , -24);
    case 10
        $c += BitShift($string[$k + 9] , -16);
    case 9
        $c += BitShift($string[$k + 8] , -8);
       ; //>>> First byte $c is reserved for $length value
   case 8
       $b += BitShift($string[$k + 7] , -24);
   case 7
       $b += BitShift($string[$k + 6] , -16);
   case 6
       $b += BitShift($string[$k + 5] , -8);
   case 5
       $b += ($string[$k + 4]);
   case 4
       $a += BitShift($string[$k + 3] , -24);
   case 3
       $a += BitShift($string[$k + 2] , -16);
   case 2
       $a += BitShift($string[$k + 1] , -8);
   case 1
       $a += ($string[$k + 0]);
    EndSwitch

    $mix = mix($a, $b, $c);

    return $mix[2];
EndFunc



Func Mix($a, $b, $c)

    $a -= $b;
    $a -= $c;
    $a = BitXOR($a , ZeroFill($c, 13));

    $b -= $c;
    $b -= $a;
    $b = BitXOR($b , BitShift($a , -8));

    $c -= $a;
    $c -= $b;
    $c = BitXOR($c , ZeroFill($b, 13));

    $a -= $b;
    $a -= $c;
    $a = BitXOR($a , ZeroFill($c, 12));

    $b -= $c;
    $b -= $a;
    $b = BitXOR($b , BitShift($a , -16));

    $c -= $a;
    $c -= $b;
    $c = BitXOR($c , ZeroFill($b, 5));

    $a -= $b;
    $a -= $c;
   $a = BitXOR($a , ZeroFill($c, 3));

    $b -= $c;
    $b -= $a;
    $b = BitXOR($b , BitShift($a , -10));

    $c -= $a;
    $c -= $b;
    $c = BitXOR($c , ZeroFill($b, 15));

    Dim $array[3]
    $array[0] = $a
    $array[1] = $b
    $array[2] = $c
    return $array;
EndFunc

autoit.php

<?php

// Global Const $CHECK_WORD
define('CHECK_WORD', 0xE6359A60);
//>>>-Func-ZeroFill->>>
function ZeroFill($a, $b)
{
    $z = hexdec(80000000);

    if ($z & $a)
    {
        $a = ($a >> 1);
        $a &= (~$z);
        $a = 0x40000000;
        $a = ($a >> ($b - 1));
    }
    else
    {
        $a = ($a >> $b);
    }
    return $a;
}
//>>>-Func-Mix->>>
function Mix($a, $b, $c)
{
    $a -= $b;
    $a -= $c;
    $a ^= (ZeroFill($c, 13));

    $b -= $c;
    $b -= $a;
    $b ^= ($a << 8);

    $c -= $a;
    $c -= $b;
    $c ^= (ZeroFill($b, 13));

    $a -= $b;
    $a -= $c;
    $a ^= (ZeroFill($c, 12));

    $b -= $c;
    $b -= $a;
    $b ^= ($a << 16);

    $c -= $a;
    $c -= $b;
    $c ^= (ZeroFill($b, 5));

    $a -= $b;
    $a -= $c;
    $a ^= (ZeroFill($c, 3));

    $b -= $c;
    $b -= $a;
    $b ^= ($a << 10);

    $c -= $a;
    $c -= $b;
    $c ^= (ZeroFill($b, 15));

    return array($a, $b, $c);
}
//>>>-Func-CheckSum->>>
function CheckSum($string, $length = null, $init = CHECK_WORD)
{
    //I think that this If statement really needed only for check value from form
    if (is_null($length))
    {
        $length = sizeof($string);
    }

    $a = $b = 0x9E3779B9;
    $c = $init;
    $k = 0;
    $len = $length;

    while($len >= 12)
    {
        $a += ($string[$k + 0] + ($string[$k + 1] << 8) + ($string[$k + 2] << 16) + ($string[$k + 3] << 24));
        $b += ($string[$k + 4] + ($string[$k + 5] << 8) + ($string[$k + 6] << 16) + ($string[$k + 7] << 24));
        $c += ($string[$k + 8] + ($string[$k + 9] << 8) + ($string[$k + 10] << 16) + ($string[$k + 11] << 24));
        $mix = mix($a, $b, $c);
        $a = $mix[0];
        $b = $mix[1];
        $c = $mix[2];
        $k += 12;
        $len -= 12;
    }

    $c += $length;

    switch ($len)
    {
        case 11: $c += ($string[$k + 10] << 24);
        case 10: $c += ($string[$k + 9] << 16);
        case 9 : $c += ($string[$k + 8] << 8);
        //>>> First byte $c is reserved for $length value
        case 8 : $b += ($string[$k + 7] << 24);
        case 7 : $b += ($string[$k + 6] << 16);
        case 6 : $b += ($string[$k + 5] << 8);
        case 5 : $b += ($string[$k + 4]);
        case 4 : $a += ($string[$k + 3] << 24);
        case 3 : $a += ($string[$k + 2] << 16);
        case 2 : $a += ($string[$k + 1] << 8);
        case 1 : $a += ($string[$k + 0]);
    }

    $mix = mix($a, $b, $c);

    return $mix[2];
}


if ($_POST) {
$R = CheckSum($_POST["DATAl"]["string"]);
print($R);
}



?>

<form action="" method="post">
    string:  <input type="text" name="DATAl[string]" VALUE="123456789123456789123456" /><br />
    <input type="submit" value="Call CheckSum function" />
</form>

صرح السماء كان هنا

 

Link to comment
Share on other sites

2PsaltyDS:

You can too...

Yes, I can but this is not help mе with AutoIt's limits for integer value... :)

2wolf9228:

GREAT THANXS for example but this is not work...

I spend a lot of time for optimize PHP-code but main problem is in AutoIt's limits for integer value...

For example:

Real integer value after byte-wise operations on PHP is "-1878480400"

The same integer value after byte-wise operations on AutoIt is "-16" and script is composed right without errors(100% GUARANTEE!!!)

Well, I'm really tired by protracted testing, how I can resolve this problem?

Link to comment
Share on other sites

2PsaltyDS:

Yes, I can but this is not help mе with AutoIt's limits for integer value... :)

2wolf9228:

GREAT THANXS for example but this is not work...

I spend a lot of time for optimize PHP-code but main problem is in AutoIt's limits for integer value...

For example:

Real integer value after byte-wise operations on PHP is "-1878480400"

The same integer value after byte-wise operations on AutoIt is "-16" and script is composed right without errors(100% GUARANTEE!!!)

Well, I'm really tired by protracted testing, how I can resolve this problem?

Can you narrow it down to a particular byte-wise operation? A short AutoIt script that demonstrates a particular operation's symptom would help. Some bit-wise examples:
Global $iVar = -1878480400
ConsoleWrite("$iVar = " & $iVar & " = 0x" & Hex($iVar) & @LF)
$iTest = BitNOT($iVar)
ConsoleWrite("BitNOT($iVar): $iTest = " & $iTest & " = 0x" & Hex($iTest) & @LF)
$iTest = BitShift($iVar, 4)
ConsoleWrite("BitShift($iVar, 4): $iTest = " & $iTest & " = 0x" & Hex($iTest) & @LF)
$iTest = BitShift($iVar, -4)
ConsoleWrite("BitShift($iVar, -4): $iTest = " & $iTest & " = 0x" & Hex($iTest) & @LF)
$iTest = BitXOR($iVar, 0xFFFF0000)
ConsoleWrite("BitXOR($iVar, 0xFFFF0000): $iTest = " & $iTest & " = 0x" & Hex($iTest) & @LF)

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

HEH!!! :P

Today I found where is main problem - in magical web-filters :)

In func ZeroFill must be a this string

$a |= 0x40000000;

not

$a = 0x40000000;

I'm sure that I just copy/paste PHP source(NO EDIT!) and submit a form, therefore it is a mystery for me... :)

Well, now integer values in both versions of scripts are identical and I thanx all who was help me with it.

Edited by TranZ
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...