Related to PHP

Started by !, Jul 11, 2017, 10:40 AM

Previous topic - Next topic

!

Guys i am new to PHP.
I've tried to convert this to PHP but its not working

function Encrypt( $string )
{
$hp =
[
0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a,
0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19
];

$k =
[
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
];

$w = array( 64 );
$i = 0;
$s = 0;
$len = $string.len( );
$word_array = array( 0 );

for( $i = 0; $i < $len - 3; $i += 4 )
{
array_push( $word_array, $string[$i] << 0x18 | $string[$i + 1] << 0x10 | $string[$i + 2] << 0x08 | $string[$i + 3] );
}

switch( $len % 4 )
{
case 0:
$i = 0x80000000;
break;
case 1:
$i = $string[$len - 1] << 0x18 | 0x80000000;
break;
case 2:
$i = $string[$len - 2] << 0x18 | $string[$len - 1] << 0x10 | 0x08000;
break;
case 3:
$i = $string[$len - 3] << 0x18 | $string[$len - 2] << 0x10 | $string[$len - 1] << 0x08 | 0x80;
break;
}
array_push( $word_array, $i );

while( ( $word_array.len() % 0x10 ) != 0x0E ) { array_push( $word_array, 0 ); }

array_push( $word_array, $len >> 0x10 );
array_push( $word_array, $len << 0x03 ) & 0xFFFFFFFF );

$s0;
$s1;
for( $s = 0; $s < $word_array.len(); $s += 0x10 )
{
for( $i = 0x00; $i < 0x10; $i++ ) { $w[$i] = $word_array[$s + $i]; }

for( $i = 0x10; $i < 0x40; $i++ )
{
$s0 = rotateRight( $w[$i - 15], 7 ) ^ rotateRight( $w[$i - 15], 18 ) ^ ( $w[$i - 15] >> 3 );
$s1 = rotateRight( $w[$i - 2], 17 ) ^ rotateRight( $w[$i - 2], 19 ) ^ ( $w[$i - 2] >> 10 );
$w[$i] = $w[$i - 0x10] + $s0 + $w[$i - 7] + $s1;
}

$a = $hp[0];
$b = $hp[1];
$c = $hp[2];
$d = $hp[3];
$e = $hp[4];
$f = $hp[5];
$g = $hp[6];
$h = $hp[7];

for( $i = 0x00; $i < 0x40; $i++ )
{
$s0 = ( rotateRight( $a, 2 ) ^ rotateRight( $a, 13 ) ^ rotateRight( $a, 22 ) );
$maj = ( ( $a & $b ) ^ ( $a & $c ) ^ ( $b & $c ) );
$t2  = ( $s0 + $maj );
$s1 = ( rotateRight( $e, 6 ) ^ rotateRight( $e, 11) ^ rotateRight( $e, 25 ) );
$ch  = ( ( $e & $f ) ^ ( ( ~$e ) & $g ) );
$t1  = ( $h + $s1 + $ch + $k[$i] + $w[$i] );

$h = $g;
$g = $f;
$f = $e;
$e = $d + $t1;
$d = $c;
$c = $b;
$b = $a;
$a = $t1 + $t2;
}

$hp[0] += $a;
$hp[1] += $b;
$hp[2] += $c;
$hp[3] += $d;
$hp[4] += $e;
$hp[5] += $f;
$hp[6] += $g;
$hp[7] += $h;
}

$hash = format
(
"%08x%08x%08x%08x%08x%08x%08x%08x",
$hp[0],
$hp[1],
$hp[2],
$hp[3],
$hp[4],
$hp[5],
$hp[6],
$hp[7]
);

return $hash;
}

By using this nothing happens
echo  Encrypt( "123blabla" );

I really need this encryption :)

For Spammers
Dont post shits like use php encryption.

Discord: zeus#5155

NicusorN5

Uhh. use ''local $variable = value'?

!

Quote from: NicusorN5 on Jul 11, 2017, 10:57 AMUhh. use ''local $variable = value'?

 :( Not working
function Encrypt( $string )
{
local $hp =
[
0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a,
0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19
];

local $k =
[
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
];

local
$w = array( 64 ),
$i = 0,
$s = 0,
$len = $string.len( ),
$word_array = array( 0 );

for( $i = 0; $i < $len - 3; $i += 4 )
{
array_push( $word_array, $string[$i] << 0x18 | $string[$i + 1] << 0x10 | $string[$i + 2] << 0x08 | $string[$i + 3] );
}

switch( $len % 4 )
{
case 0:
$i = 0x80000000;
break;
case 1:
$i = $string[$len - 1] << 0x18 | 0x80000000;
break;
case 2:
$i = $string[$len - 2] << 0x18 | $string[$len - 1] << 0x10 | 0x08000;
break;
case 3:
$i = $string[$len - 3] << 0x18 | $string[$len - 2] << 0x10 | $string[$len - 1] << 0x08 | 0x80;
break;
}
array_push( $word_array, $i );

while( ( $word_array.len() % 0x10 ) != 0x0E ) { array_push( $word_array, 0 ); }

array_push( $word_array, $len >> 0x10 );
array_push( $word_array, $len << 0x03 ) & 0xFFFFFFFF );

local $s0, $s1;
for( $s = 0; $s < $word_array.len(); $s += 0x10 )
{
for( $i = 0x00; $i < 0x10; $i++ ) { $w[$i] = $word_array[$s + $i]; }

for( $i = 0x10; $i < 0x40; $i++ )
{
$s0 = rotateRight( $w[$i - 15], 7 ) ^ rotateRight( $w[$i - 15], 18 ) ^ ( $w[$i - 15] >> 3 );
$s1 = rotateRight( $w[$i - 2], 17 ) ^ rotateRight( $w[$i - 2], 19 ) ^ ( $w[$i - 2] >> 10 );
$w[$i] = $w[$i - 0x10] + $s0 + $w[$i - 7] + $s1;
}

local
$a = $hp[0],
$b = $hp[1],
$c = $hp[2],
$d = $hp[3],
$e = $hp[4],
$f = $hp[5],
$g = $hp[6],
$h = $hp[7];

for( $i = 0x00; $i < 0x40; $i++ )
{
$s0 = ( rotateRight( $a, 2 ) ^ rotateRight( $a, 13 ) ^ rotateRight( $a, 22 ) );
local $maj = ( ( $a & $b ) ^ ( $a & $c ) ^ ( $b & $c ) );
local $t2  = ( $s0 + $maj );
$s1 = ( rotateRight( $e, 6 ) ^ rotateRight( $e, 11) ^ rotateRight( $e, 25 ) );
local $ch  = ( ( $e & $f ) ^ ( ( ~$e ) & $g ) );
local $t1  = ( $h + $s1 + $ch + $k[$i] + $w[$i] );

$h = $g;
$g = $f;
$f = $e;
$e = $d + $t1;
$d = $c;
$c = $b;
$b = $a;
$a = $t1 + $t2;
}

$hp[0] += $a;
$hp[1] += $b;
$hp[2] += $c;
$hp[3] += $d;
$hp[4] += $e;
$hp[5] += $f;
$hp[6] += $g;
$hp[7] += $h;
}

local $hash = format
(
"%08x%08x%08x%08x%08x%08x%08x%08x",
$hp[0],
$hp[1],
$hp[2],
$hp[3],
$hp[4],
$hp[5],
$hp[6],
$hp[7]
);

return $hash;
}

Discord: zeus#5155

EK.IceFlake

Quote from: NicusorN5 on Jul 11, 2017, 10:57 AMUhh. use ''local $variable = value'?
In PHP you don't need to (and can't) declare variables.

ysc3839

Could you tell me why you need this encryption algorithm?

NicusorN5

Quote from: EK.IceFlake on Jul 11, 2017, 12:42 PM
Quote from: NicusorN5 on Jul 11, 2017, 10:57 AMUhh. use ''local $variable = value'?
In PHP you don't need to (and can't) declare variables.
I tought it was squirrel. xD

!

Quote from: ysc3839 on Jul 11, 2017, 01:35 PMCould you tell me why you need this encryption algorithm?
Used in my server creating ucp for users in webstats.

Discord: zeus#5155

Thijn

Then use a normal encryption that's widely used and proven to be safe.

!

Quote from: Thijn on Jul 11, 2017, 04:59 PMThen use a normal encryption that's widely used and proven to be safe.
Well i am trying to let users login to UCP with same passwards as they've used in server.I thaught its possible to convert this encryption to php but it's not working.

Discord: zeus#5155

!

Is this function(format()) availabe in PHP

$hash = format
   (
   "%08x%08x%08x%08x%08x%08x%08x%08x",
   $hp[0],
   $hp[1],
   $hp[2],
   $hp[3],
   $hp[4],
   $hp[5],
   $hp[6],
   $hp[7]
   );

Discord: zeus#5155

EK.IceFlake

Try this:
<?php
function Encrypt$string )
{
    
$hp =
    [
    
0x6a09e6670xbb67ae850x3c6ef3720xa54ff53a,
    
0x510e527f0x9b05688c0x1f83d9ab0x5be0cd19
    
];

    
$k =
    [
    
0x428a2f980x713744910xb5c0fbcf0xe9b5dba50x3956c25b0x59f111f10x923f82a40xab1c5ed5,
    
0xd807aa980x12835b010x243185be0x550c7dc30x72be5d740x80deb1fe0x9bdc06a70xc19bf174,
    
0xe49b69c10xefbe47860x0fc19dc60x240ca1cc0x2de92c6f0x4a7484aa0x5cb0a9dc0x76f988da,
    
0x983e51520xa831c66d0xb00327c80xbf597fc70xc6e00bf30xd5a791470x06ca63510x14292967,
    
0x27b70a850x2e1b21380x4d2c6dfc0x53380d130x650a73540x766a0abb0x81c2c92e0x92722c85,
    
0xa2bfe8a10xa81a664b0xc24b8b700xc76c51a30xd192e8190xd69906240xf40e35850x106aa070,
    
0x19a4c1160x1e376c080x2748774c0x34b0bcb50x391c0cb30x4ed8aa4a0x5b9cca4f0x682e6ff3,
    
0x748f82ee0x78a5636f0x84c878140x8cc702080x90befffa0xa4506ceb0xbef9a3f70xc67178f2
    
];

    
$w = [];
    
$i 0;
    
$s 0;
    
$len strlen($string);
    
$word_array = [];

    for( 
$i 0$i $len 3$i += )
    {
        
$word_array[] = $string[$i] << 0x18 $string[$i 1] << 0x10 $string[$i 2] << 0x08 $string[$i 3];
    }

    switch( 
$len )
    {
    case 
0:
    
$i 0x80000000;
    break;
    case 
1:
    
$i ord(substr($string$len 11)) << 0x18 0x80000000;
    break;
    case 
2:
    
$i ord(substr($string$len 21)) << 0x18 ord(substr($string$len 11)) << 0x10 0x08000;//here
    
break;
    case 
3:
    
$i $string[$len 3] << 0x18 $string[$len 2] << 0x10 $string[$len 1] << 0x08 0x80;
    break;
    }
    
$word_array[] = $i;

    while( ( 
count($word_array) % 0x10 ) != 0x0E ) { $word_array[] = 0; }

    
$word_array[] = $len >> 0x10 ;
    
$word_array[] = ($len << 0x03) & 0xFFFFFFFF;

    
$s0;
    
$s1;

    for( 
$s 0$s count($word_array); $s += 0x10 )
    {
    for( 
$i 0x00$i 0x10$i++ ) { $w[$i] = $word_array[$s $i]; }

    for( 
$i 0x10$i 0x40$i++ )
    {
    
$s0 rotateRight$w[$i 15], ) ^ rotateRight$w[$i 15], 18 ) ^ ( $w[$i 15] >> );
    
$s1 rotateRight$w[$i 2], 17 ) ^ rotateRight$w[$i 2], 19 ) ^ ( $w[$i 2] >> 10 );
    
$w[$i] = $w[$i 0x10] + $s0 $w[$i 7] + $s1;
    }

    
$a $hp[0];
    
$b $hp[1];
    
$c $hp[2];
    
$d $hp[3];
    
$e $hp[4];
    
$f $hp[5];
    
$g $hp[6];
    
$h $hp[7];

    for( 
$i 0x00$i 0x40$i++ )
    {
    
$s0 = ( rotateRight$a) ^ rotateRight$a13 ) ^ rotateRight$a22 ) );
    
$maj = ( ( $a $b ) ^ ( $a $c ) ^ ( $b $c ) );
    
$t2  = ( $s0 $maj );
    
$s1 = ( rotateRight$e) ^ rotateRight$e11) ^ rotateRight$e25 ) );
    
$ch  = ( ( $e $f ) ^ ( ( ~$e ) & $g ) );
    
$t1  = ( $h $s1 $ch $k[$i] + $w[$i] );

    
$h $g;
    
$g $f;
    
$f $e;
    
$e $d $t1;
    
$d $c;
    
$c $b;
    
$b $a;
    
$a $t1 $t2;
    }

    
$hp[0] += $a;
    
$hp[1] += $b;
    
$hp[2] += $c;
    
$hp[3] += $d;
    
$hp[4] += $e;
    
$hp[5] += $f;
    
$hp[6] += $g;
    
$hp[7] += $h;
    }

    return 
implode(""$hp);
}

And make sure you port over your rotateRight function.

!

Quote from: EK.IceFlake on Jul 12, 2017, 08:32 AMTry this:
...
And make sure you port over your rotateRight function.
Thx @EK.IceFlake  but this doesn't add the string the output is something like this
Quote12345 returns
8.7861090275141E+213.6833282875952E+215.5685565521547E+214.6909687980601E+211.4228493143887E+225.9748002442625E+219.0528085310396E+217.6357735793857E+21

I thaught the format() and len() function is available in php i was wrong.
This is what i've tried but it doesn't returns the same string as in squirrel
Both returns changed string.

[spoiler=PHP_Encryption]
<?php
 
echo Encrypt"12345" );

function 
Encrypt$string )
{
$hp =
[
0x6a09e6670xbb67ae850x3c6ef3720xa54ff53a,
0x510e527f0x9b05688c0x1f83d9ab0x5be0cd19
];

$k =
[
0x428a2f980x713744910xb5c0fbcf0xe9b5dba50x3956c25b0x59f111f10x923f82a40xab1c5ed5,
0xd807aa980x12835b010x243185be0x550c7dc30x72be5d740x80deb1fe0x9bdc06a70xc19bf174,
0xe49b69c10xefbe47860x0fc19dc60x240ca1cc0x2de92c6f0x4a7484aa0x5cb0a9dc0x76f988da,
0x983e51520xa831c66d0xb00327c80xbf597fc70xc6e00bf30xd5a791470x06ca63510x14292967,
0x27b70a850x2e1b21380x4d2c6dfc0x53380d130x650a73540x766a0abb0x81c2c92e0x92722c85,
0xa2bfe8a10xa81a664b0xc24b8b700xc76c51a30xd192e8190xd69906240xf40e35850x106aa070,
0x19a4c1160x1e376c080x2748774c0x34b0bcb50x391c0cb30x4ed8aa4a0x5b9cca4f0x682e6ff3,
0x748f82ee0x78a5636f0x84c878140x8cc702080x90befffa0xa4506ceb0xbef9a3f70xc67178f2
];

$w  = array( 64 );
$i  = 0;
$s  = 0;
$len strlen($string);
$word_array = array( );

for( $i 0$i $len 3$i += )
{
array_push$word_array$string[$i] << 0x18 $string[$i 1] << 0x10 $string[$i 2] << 0x08 $string[$i 3] );
}

switch( $len )
{
case 0:
$i 0x80000000;
break;
case 1:
$i $string[$len 1] << 0x18 0x80000000;
break;
case 2:
$i $string[$len 2] << 0x18 $string[$len 1] << 0x10 0x08000;
break;
case 3:
$i $string[$len 3] << 0x18 $string[$len 2] << 0x10 $string[$len 1] << 0x08 0x80;
break;
}
array_push$word_array$i );

while( ( count($word_array) % 0x10 ) != 0x0E ) { array_push$word_array); }

array_push$word_array$len >> 0x10 );
array_push$word_array$len << 0x03 0xFFFFFFFF );

$s0;
$s1;
for( $s 0$s count($word_array); $s += 0x10 )
{
for( $i 0x00$i 0x10$i++ ) { $w[$i] = $word_array[$s $i]; }

for( $i 0x10$i 0x40$i++ )
{
$s0 rotateRight$w[$i 15], ) ^ rotateRight$w[$i 15], 18 ) ^ ( $w[$i 15] >> );
$s1 rotateRight$w[$i 2], 17 ) ^ rotateRight$w[$i 2], 19 ) ^ ( $w[$i 2] >> 10 );
$w[$i] = $w[$i 0x10] + $s0 $w[$i 7] + $s1;
  }

$a $hp[0];
$b $hp[1];
$c $hp[2];
$d $hp[3];
$e $hp[4];
$f $hp[5];
$g $hp[6];
$h $hp[7];

for( $i 0x00$i 0x40$i++ )
{
$s0 = ( rotateRight$a) ^ rotateRight$a13 ) ^ rotateRight$a22 ) );
$maj = ( ( $a $b ) ^ ( $a $c ) ^ ( $b $c ) );
$t2  = ( $s0 $maj );
$s1 = ( rotateRight$e) ^ rotateRight$e11) ^ rotateRight$e25 ) );
$ch  = ( ( $e $f ) ^ ( ( ~$e ) & $g ) );
$t1  = ( $h $s1 $ch $k[$i] + $w[$i] );

$h $g;
$g $f;
$f $e;
$e $d $t1;
$d $c;
$c $b;
$b $a;
$a $t1 $t2;
}

$hp[0] += $a;
$hp[1] += $b;
$hp[2] += $c;
$hp[3] += $d;
$hp[4] += $e;
$hp[5] += $f;
$hp[6] += $g;
$hp[7] += $h;
}

$hash sprintf
(
"%08x%08x%08x%08x%08x%08x%08x%08x",
$hp[0],
$hp[1],
$hp[2],
$hp[3],
$hp[4],
$hp[5],
$hp[6],
$hp[7]
);

return $hash;
}

function 
rotateRight($val$sbits)
{
return ($val >> $sbits) | ($val << (0x20 $sbits) );
}
[/spoiler]

[spoiler=Squirrel_Encryption]
print( Encrypt( "12345" ) );

function Encrypt( string )
{
local hp =
[
0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a,
0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19
];

local k =
[
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
];

local
w = array( 64 ),
i = 0,
s = 0,
len = string.len( ),
word_array = array( 0 );

for( i = 0; i < len - 3; i += 4 )
{
word_array.push( string[i] << 0x18 | string[i + 1] << 0x10 | string[i + 2] << 0x08 | string[i + 3] );
}

switch( len % 4 )
{
case 0:
i = 0x80000000;
break;
case 1:
i = string[len - 1] << 0x18 | 0x80000000;
break;
case 2:
i = string[len - 2] << 0x18 | string[len - 1] << 0x10 | 0x08000;
break;
case 3:
i = string[len - 3] << 0x18 | string[len - 2] << 0x10 | string[len - 1] << 0x08 | 0x80;
break;
}
word_array.push( i );

while( ( word_array.len() % 0x10 ) != 0x0E )
word_array.push( 0 );

word_array.push( len >> 0x10 );
word_array.push( ( len << 0x03 ) & 0xFFFFFFFF );

local s0, s1;
for( s = 0; s < word_array.len(); s += 0x10 )
{
for( i = 0x00; i < 0x10; i++ )
w[i] = word_array[s + i];

for( i = 0x10; i < 0x40; i++ )
{
s0 = rotateRight( w[i - 15], 7 ) ^ rotateRight( w[i - 15], 18 ) ^ ( w[i - 15] >> 3 );
s1 = rotateRight( w[i - 2], 17 ) ^ rotateRight( w[i - 2], 19 ) ^ ( w[i - 2] >> 10 );
w[i] = w[i - 0x10] + s0 + w[i - 7] + s1;
}

local a = hp[0],
b = hp[1],
c = hp[2],
d = hp[3],
e = hp[4],
f = hp[5],
g = hp[6],
h = hp[7];

for( i = 0x00; i < 0x40; i++ )
{
s0 = ( rotateRight( a, 2 ) ^ rotateRight( a, 13 ) ^ rotateRight( a, 22 ) );
local maj = ( ( a & b ) ^ ( a & c ) ^ ( b & c ) );
local t2  = ( s0 + maj );
s1 = ( rotateRight( e, 6 ) ^ rotateRight( e, 11) ^ rotateRight( e, 25 ) );
local ch  = ( ( e & f ) ^ ( ( ~e ) & g ) );
local t1  = ( h + s1 + ch + k[i] + w[i] );

h = g;
g = f;
f = e;
e = d + t1;
d = c;
c = b;
b = a;
a = t1 + t2;
}

hp[0] += a;
hp[1] += b;
hp[2] += c;
hp[3] += d;
hp[4] += e;
hp[5] += f;
hp[6] += g;
hp[7] += h;
}

local hash = format
(
"%08x%08x%08x%08x%08x%08x%08x%08x",
hp[0],
hp[1],
hp[2],
hp[3],
hp[4],
hp[5],
hp[6],
hp[7]
);

return hash;
}

function rotateRight(val, sbits)
{
return (val >> sbits) | (val << (0x20 - sbits) );
}
[/spoiler]

Discord: zeus#5155

EK.IceFlake

#12
Quote from: zeus on Jul 12, 2017, 11:18 AM
Quote from: EK.IceFlake on Jul 12, 2017, 08:32 AMTry this:
...
And make sure you port over your rotateRight function.
Thx @EK.IceFlake  but this doesn't add the string the output is something like this
Quote12345 returns
8.7861090275141E+213.6833282875952E+215.5685565521547E+214.6909687980601E+211.4228493143887E+225.9748002442625E+219.0528085310396E+217.6357735793857E+21

I thaught the format() and len() function is available in php i was wrong.
This is what i've tried but it doesn't returns the same string as in squirrel
Both returns changed string.

[spoiler=PHP_Encryption]
<?php
 
echo Encrypt"12345" );

function 
Encrypt$string )
{
$hp =
[
0x6a09e6670xbb67ae850x3c6ef3720xa54ff53a,
0x510e527f0x9b05688c0x1f83d9ab0x5be0cd19
];

$k =
[
0x428a2f980x713744910xb5c0fbcf0xe9b5dba50x3956c25b0x59f111f10x923f82a40xab1c5ed5,
0xd807aa980x12835b010x243185be0x550c7dc30x72be5d740x80deb1fe0x9bdc06a70xc19bf174,
0xe49b69c10xefbe47860x0fc19dc60x240ca1cc0x2de92c6f0x4a7484aa0x5cb0a9dc0x76f988da,
0x983e51520xa831c66d0xb00327c80xbf597fc70xc6e00bf30xd5a791470x06ca63510x14292967,
0x27b70a850x2e1b21380x4d2c6dfc0x53380d130x650a73540x766a0abb0x81c2c92e0x92722c85,
0xa2bfe8a10xa81a664b0xc24b8b700xc76c51a30xd192e8190xd69906240xf40e35850x106aa070,
0x19a4c1160x1e376c080x2748774c0x34b0bcb50x391c0cb30x4ed8aa4a0x5b9cca4f0x682e6ff3,
0x748f82ee0x78a5636f0x84c878140x8cc702080x90befffa0xa4506ceb0xbef9a3f70xc67178f2
];

$w  = array( 64 );
$i  = 0;
$s  = 0;
$len strlen($string);
$word_array = array( );

for( $i 0$i $len 3$i += )
{
array_push$word_array$string[$i] << 0x18 $string[$i 1] << 0x10 $string[$i 2] << 0x08 $string[$i 3] );
}

switch( $len )
{
case 0:
$i 0x80000000;
break;
case 1:
$i $string[$len 1] << 0x18 0x80000000;
break;
case 2:
$i $string[$len 2] << 0x18 $string[$len 1] << 0x10 0x08000;
break;
case 3:
$i $string[$len 3] << 0x18 $string[$len 2] << 0x10 $string[$len 1] << 0x08 0x80;
break;
}
array_push$word_array$i );

while( ( count($word_array) % 0x10 ) != 0x0E ) { array_push$word_array); }

array_push$word_array$len >> 0x10 );
array_push$word_array$len << 0x03 0xFFFFFFFF );

$s0;
$s1;
for( $s 0$s count($word_array); $s += 0x10 )
{
for( $i 0x00$i 0x10$i++ ) { $w[$i] = $word_array[$s $i]; }

for( $i 0x10$i 0x40$i++ )
{
$s0 rotateRight$w[$i 15], ) ^ rotateRight$w[$i 15], 18 ) ^ ( $w[$i 15] >> );
$s1 rotateRight$w[$i 2], 17 ) ^ rotateRight$w[$i 2], 19 ) ^ ( $w[$i 2] >> 10 );
$w[$i] = $w[$i 0x10] + $s0 $w[$i 7] + $s1;
  }

$a $hp[0];
$b $hp[1];
$c $hp[2];
$d $hp[3];
$e $hp[4];
$f $hp[5];
$g $hp[6];
$h $hp[7];

for( $i 0x00$i 0x40$i++ )
{
$s0 = ( rotateRight$a) ^ rotateRight$a13 ) ^ rotateRight$a22 ) );
$maj = ( ( $a $b ) ^ ( $a $c ) ^ ( $b $c ) );
$t2  = ( $s0 $maj );
$s1 = ( rotateRight$e) ^ rotateRight$e11) ^ rotateRight$e25 ) );
$ch  = ( ( $e $f ) ^ ( ( ~$e ) & $g ) );
$t1  = ( $h $s1 $ch $k[$i] + $w[$i] );

$h $g;
$g $f;
$f $e;
$e $d $t1;
$d $c;
$c $b;
$b $a;
$a $t1 $t2;
}

$hp[0] += $a;
$hp[1] += $b;
$hp[2] += $c;
$hp[3] += $d;
$hp[4] += $e;
$hp[5] += $f;
$hp[6] += $g;
$hp[7] += $h;
}

$hash sprintf
(
"%08x%08x%08x%08x%08x%08x%08x%08x",
$hp[0],
$hp[1],
$hp[2],
$hp[3],
$hp[4],
$hp[5],
$hp[6],
$hp[7]
);

return $hash;
}

function 
rotateRight($val$sbits)
{
return ($val >> $sbits) | ($val << (0x20 $sbits) );
}
[/spoiler]

[spoiler=Squirrel_Encryption]
print( Encrypt( "12345" ) );

function Encrypt( string )
{
local hp =
[
0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a,
0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19
];

local k =
[
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
];

local
w = array( 64 ),
i = 0,
s = 0,
len = string.len( ),
word_array = array( 0 );

for( i = 0; i < len - 3; i += 4 )
{
word_array.push( string[i] << 0x18 | string[i + 1] << 0x10 | string[i + 2] << 0x08 | string[i + 3] );
}

switch( len % 4 )
{
case 0:
i = 0x80000000;
break;
case 1:
i = string[len - 1] << 0x18 | 0x80000000;
break;
case 2:
i = string[len - 2] << 0x18 | string[len - 1] << 0x10 | 0x08000;
break;
case 3:
i = string[len - 3] << 0x18 | string[len - 2] << 0x10 | string[len - 1] << 0x08 | 0x80;
break;
}
word_array.push( i );

while( ( word_array.len() % 0x10 ) != 0x0E )
word_array.push( 0 );

word_array.push( len >> 0x10 );
word_array.push( ( len << 0x03 ) & 0xFFFFFFFF );

local s0, s1;
for( s = 0; s < word_array.len(); s += 0x10 )
{
for( i = 0x00; i < 0x10; i++ )
w[i] = word_array[s + i];

for( i = 0x10; i < 0x40; i++ )
{
s0 = rotateRight( w[i - 15], 7 ) ^ rotateRight( w[i - 15], 18 ) ^ ( w[i - 15] >> 3 );
s1 = rotateRight( w[i - 2], 17 ) ^ rotateRight( w[i - 2], 19 ) ^ ( w[i - 2] >> 10 );
w[i] = w[i - 0x10] + s0 + w[i - 7] + s1;
}

local a = hp[0],
b = hp[1],
c = hp[2],
d = hp[3],
e = hp[4],
f = hp[5],
g = hp[6],
h = hp[7];

for( i = 0x00; i < 0x40; i++ )
{
s0 = ( rotateRight( a, 2 ) ^ rotateRight( a, 13 ) ^ rotateRight( a, 22 ) );
local maj = ( ( a & b ) ^ ( a & c ) ^ ( b & c ) );
local t2  = ( s0 + maj );
s1 = ( rotateRight( e, 6 ) ^ rotateRight( e, 11) ^ rotateRight( e, 25 ) );
local ch  = ( ( e & f ) ^ ( ( ~e ) & g ) );
local t1  = ( h + s1 + ch + k[i] + w[i] );

h = g;
g = f;
f = e;
e = d + t1;
d = c;
c = b;
b = a;
a = t1 + t2;
}

hp[0] += a;
hp[1] += b;
hp[2] += c;
hp[3] += d;
hp[4] += e;
hp[5] += f;
hp[6] += g;
hp[7] += h;
}

local hash = format
(
"%08x%08x%08x%08x%08x%08x%08x%08x",
hp[0],
hp[1],
hp[2],
hp[3],
hp[4],
hp[5],
hp[6],
hp[7]
);

return hash;
}

function rotateRight(val, sbits)
{
return (val >> sbits) | (val << (0x20 - sbits) );
}
[/spoiler]
1.
.len()
You use strlen(...) if it's a string and count(...) if it's an array.

2.
format
You seem to want to convert it to a hex string.
That'd be dechex.

!

Quote from: EK.IceFlake on Jul 12, 2017, 12:07 PM1.
.len()
You use strlen(...) if it's a string and count(...) if it's an array.
Got this one but still confused in 2nd one.
dechex completely change the output, where i've to use this.
Quote from: EK.IceFlake on Jul 12, 2017, 12:07 PM2.
format
You seem to want to convert it to a hex string.
That'd be dechex.

http://phptester.net/

Discord: zeus#5155

EK.IceFlake

Quote from: zeus on Jul 12, 2017, 02:20 PM
Quote from: EK.IceFlake on Jul 12, 2017, 12:07 PM1.
.len()
You use strlen(...) if it's a string and count(...) if it's an array.
Got this one but still confused in 2nd one.
dechex completely change the output, where i've to use this.
Quote from: EK.IceFlake on Jul 12, 2017, 12:07 PM2.
format
You seem to want to convert it to a hex string.
That'd be dechex.

http://phptester.net/
The different output is most likely you using array(64) and the likes. In PHP, array(x) is the equivalent of [x]. Instead, you simply want to declare it as []. PHP will automatically create indexes that don't exist.