Post Pacific  

Go Back   Post Pacific > Восстановленный архив > Темы без сохранившегося раздела

Notices

 
 
Thread Tools Search this Thread Display Modes
Old 08.04.2007, 22:32   #1
predatorx
Архивный участник
 
Join Date: Aug 2006
Posts: 5
Default password encrypt algorithm.

Hi ppl..

the password encrypt is a public algorithm??

not is MD5...


somebody knows that algorithm is ...?

this question came to my mind, when i change asp to php

thx
predatorx is offline  
Old 08.04.2007, 22:41   #2
dirkr
Архивный участник
 
Join Date: Nov 2006
Posts: 204
Default

Code:
function encrypt($str) {
	$key = array();
	$dst = array();
	$i = 0;

	$nBytes = strlen($str);
        	while ($i < $nBytes){
               	 $i++;
                	$key[$i] = ord(substr($str, $i - 1, 1));
                	$dst[$i] = $key[$i];
	}  

	$rslt = $key[1] + $key[2]*256 + $key[3]*65536 + $key[4]*16777216;
	$one = $rslt * 213119 + 2529077;
	$one = $one - intval($one/ 4294967296) * 4294967296;

	$rslt = $key[5] + $key[6]*256 + $key[7]*65536 + $key[8]*16777216;
	$two = $rslt * 213247 + 2529089;
	$two = $two - intval($two/ 4294967296) * 4294967296;

	$rslt = $key[9] + $key[10]*256 + $key[11]*65536 + $key[12]*16777216;
	$three = $rslt * 213203 + 2529589;
	$three = $three - intval($three/ 4294967296) * 4294967296;

	$rslt = $key[13] + $key[14]*256 + $key[15]*65536 + $key[16]*16777216;
	$four = $rslt * 213821 + 2529997;
	$four = $four - intval($four/ 4294967296) * 4294967296;

	$key[4] = intval($one/16777216);        
	$key[3] = intval(($one - $key[4] * 16777216) / 65535);
	$key[2] = intval(($one - $key[4] * 16777216 - $key[3] * 65536) / 256);
	$key[1] = intval(($one - $key[4] * 16777216 - $key[3] * 65536 - $key[2] * 256));

	$key[8] = intval($two/16777216);     
	$key[7] = intval(($two - $key[8] * 16777216) / 65535);
	$key[6] = intval(($two - $key[8] * 16777216 - $key[7] * 65536) / 256);
	$key[5] = intval(($two - $key[8] * 16777216 - $key[7] * 65536 - $key[6] * 256));

	$key[12] = intval($three/16777216);     
	$key[11] = intval(($three - $key[12] * 16777216) / 65535);
	$key[10] = intval(($three - $key[12] * 16777216 - $key[11] * 65536) / 256);
	$key[9] = intval(($three - $key[12] * 16777216 - $key[11] * 65536 - $key[10] * 256));

	$key[16] = intval($four/16777216);     
	$key[15] = intval(($four - $key[16] * 16777216) / 65535);
	$key[14] = intval(($four - $key[16] * 16777216 - $key[15] * 65536) / 256);
	$key[13] = intval(($four - $key[16] * 16777216 - $key[15] * 65536 - $key[14] * 256));

	$dst[1] = $dst[1] ^ $key[1];

	$i=1;
	while ($i<16){
		$i++;
		$dst[$i] = $dst[$i] ^ $dst[$i-1] ^ $key[$i];
	}

	$i=0;
	while ($i<16){
		$i++;
		if ($dst[$i] == 0) {
			$dst[$i] = 102;
		}
	}

	$encrypt = "0x";
	$i=0;
	while ($i<16){
		$i++;
		if ($dst[$i] < 16) {
			$encrypt = $encrypt . "0" . dechex($dst[$i]);
		} else {
			$encrypt = $encrypt . dechex($dst[$i]);
		}
	}

	return $encrypt;
}
dirkr is offline  
Old 15.06.2007, 07:53   #3
ateh
Архивный участник
 
Join Date: Apr 2006
Posts: 118
Default

Actually it's wrong, and as I see noone ever noticed that... :P As some of you know this function was sometimes returning wrong hash (too long, and with wrong data).
Problem is that someone put /65535 instead of /65536 and after that all people were using it without checking.

Those are correct lines:
Code:
$key[3] = intval(($one - $key[4] * 16777216) / 65536);
$key[7] = intval(($two - $key[8] * 16777216) / 65536);
$key[11] = intval(($three - $key[12] * 16777216) / 65536);
$key[15] = intval(($four - $key[16] * 16777216) / 65536);
Now it all finally works correctly ;P

Wrong code is for example used in:
https://postpacific.loc-online.com/f...hlight=encrypt
https://postpacific.loc-online.com/f...hlight=encrypt
https://postpacific.loc-online.com/f...hlight=encrypt
L2Tools 1.6 L2Control Panel.
ateh is offline  
Old 15.06.2007, 08:39   #4
Forcer
Архивный участник
 
Join Date: Apr 2006
Posts: 554
Default

Thanks, but one question.
I changed this string's and still have problem.
Look, I have made hash of password ROOT and ROOD.
And they was same!
0xb1be70e9a83f19192cb593935ec4e2e2

Im think that's abnormal, any idea?
Forcer is offline  
Old 15.06.2007, 08:46   #5
ateh
Архивный участник
 
Join Date: Apr 2006
Posts: 118
Default

Same hash for simmilar words is an other thing, it's dependant on algorith, which is just not perfect itself, so it's 'normal'. Blame NCsoft programmers for that. At least implementation is correct now :P
ateh is offline  
Old 15.06.2007, 09:00   #6
Forcer
Архивный участник
 
Join Date: Apr 2006
Posts: 554
Default

Has understood, good job.
thanks.
Forcer is offline  
Old 30.07.2007, 14:53   #7
supermamie
Архивный участник
 
Join Date: Jun 2007
Posts: 14
Default

Even with ateh's correction, I can't log on my server with L2CP.
Accounts had been made by L2 account creator.

If anyone have an idea, because I need to make something like
UPDATE user_auth SET password = blabla WHERE password=blibli AND account = bla.

thanks
supermamie is offline  
Old 30.07.2007, 19:48   #8
Kenjiro
Архивный участник
 
Join Date: Apr 2006
Posts: 120
Default

My slightly changed (simplified) version:
Code:
function password_encrypt ( $plain ) {
  $array_mul = array ( 0 => 213119, 1 => 213247, 2 => 213203, 3 => 213821 );
  $array_add = array ( 0 => 2529077, 1 => 2529089, 2 => 2529589, 3 => 2529997 );
  $dst = $key = array ( 0 => 0, 1 => 0, 2 => 0, 3 => 0, 4 => 0, 5 => 0, 6 => 0, 7 => 0, 8 => 0, 9 => 0, 10 => 0, 11 => 0, 12 => 0, 13 => 0, 14 => 0, 15 => 0 );

  for ( $i = 0; $i < strlen ( $plain ); $i++ ) {
    $dst [ $i ] = $key [ $i ] = ord ( substr ( $plain, $i, 1 ) );
  }

  for ( $i = 0; $i <= 3; $i++ ) {
    $val [ $i ] = fmod ( ( $key [ $i * 4 + 0 ] + $key [ $i * 4 + 1 ] * 0x100 + $key [ $i * 4 + 2 ] * 0x10000 + $key [ $i * 4 + 3 ] * 0x1000000 ) * $array_mul [ $i ] + $array_add [ $i ], 4294967296 );
  }

  for ( $i = 0; $i <= 3; $i++ ) {
    $key [ $i * 4 + 0 ] = $val [ $i ] & 0xff;
    $key [ $i * 4 + 1 ] = $val [ $i ] / 0x100 & 0xff;
    $key [ $i * 4 + 2 ] = $val [ $i ] / 0x10000 & 0xff;
    $key [ $i * 4 + 3 ] = $val [ $i ] / 0x1000000 & 0xff;
  }

  $dst [ 0 ] = $dst [ 0 ] ^ $key [ 0 ];
  for ( $i = 1; $i <= 15; $i++ ) {
    $dst [ $i ] = $dst [ $i ] ^ $dst [ $i - 1 ] ^ $key [ $i ];
  }

  for ( $i = 0; $i <= 15; $i++ ) {
    if ( $dst [ $i ] == 0 ) {
      $dst [ $i ] = 0x66;
    }
  }

  $encrypted = "0x";
  for ( $i = 0; $i <= 15; $i++ ) {
    if ( $dst [ $i ] < 16 ) {
      $encrypted .= "0";
    }
    $encrypted .= strtoupper ( dechex ( $dst [ $i ] ) );
  }
  return ( $encrypted );
}
And then you use:
PHP Code:
$query = "update user_auth set password=" . password_encrypt ( $new_password ) . " where password=" . password_encrypt ( $old_password ) . " and account='" . $account . "'";
$res = mssql_query ( $query ); 
Kenjiro is offline  
Old 30.07.2007, 19:58   #9
Forcer
Архивный участник
 
Join Date: Apr 2006
Posts: 554
Default

Kenjiro, that's cool.
Big thanks, +1.
I will test.
Forcer is offline  
Old 30.07.2007, 20:38   #10
supermamie
Архивный участник
 
Join Date: Jun 2007
Posts: 14
Default

Just tested, and it works great!
thank you a lot!
supermamie is offline  
Old 05.08.2007, 13:59   #11
supermamie
Архивный участник
 
Join Date: Jun 2007
Posts: 14
Default

In fact... it works great but only with passwords without numbers :/
The encryption of number is wrong so people can't play if they enter a password with numbers in it.
supermamie is offline  
Old 05.08.2007, 19:26   #12
adriahu
Архивный участник
 
Join Date: Oct 2006
Posts: 47
Default my implementation

Code:
function auth_encrypt($str) 
{
	$key = array();
	$dst = array(); 
	$i = 0; 
	$nBytes = strlen($str);
	
	while ($i < $nBytes)
	{
		$i++; 
		$key[$i] = ord(substr($str, $i - 1, 1)); 
		$dst[$i] = $key[$i];
	}
	
	$rslt  = @$key[1] + @$key[2]*256 + @$key[3]*65536 + @$key[4]*16777216;
	$one   = $rslt * 213119 + 2529077; $one = $one - intval($one/ 4294967296) * 4294967296;
	$rslt  = @$key[5] + @$key[6]*256 + @$key[7]*65536 + @$key[8]*16777216;
	$two   = $rslt * 213247 + 2529089; $two = $two - intval($two/ 4294967296) * 4294967296;
	$rslt  = @$key[9] + @$key[10]*256 + @$key[11]*65536 + @$key[12]*16777216;
	$three = $rslt * 213203 + 2529589; $three = $three - intval($three/ 4294967296) * 4294967296;
	$rslt  = @$key[13] + @$key[14]*256 + @$key[15]*65536 + @$key[16]*16777216;
	$four  = $rslt * 213821 + 2529997; $four = $four - intval($four/ 4294967296) * 4294967296;
	
	$key[4]  = intval($one/16777216); 
	$key[3]  = intval(($one - @$key[4] * 16777216) / 65535);
	$key[2]  = intval(($one - @$key[4] * 16777216 - @$key[3] * 65536) / 256);
	$key[1]  = intval(($one - @$key[4] * 16777216 - @$key[3] * 65536 - @$key[2] * 256));
	$key[8]  = intval($two/16777216); 
	$key[7]  = intval(($two - @$key[8] * 16777216) / 65535);
	$key[6]  = intval(($two - @$key[8] * 16777216 - @$key[7] * 65536) / 256);
	$key[5]  = intval(($two - @$key[8] * 16777216 - @$key[7] * 65536 - @$key[6] * 256));
	$key[12] = intval($three/16777216); 
	$key[11] = intval(($three - @$key[12] * 16777216) / 65535);
	$key[10] = intval(($three - @$key[12] * 16777216 - @$key[11] * 65536) / 256);
	$key[9]  = intval(($three - @$key[12] * 16777216 - @$key[11] * 65536 - @$key[10] * 256));
	$key[16] = intval($four/16777216); 
	$key[15] = intval(($four - @$key[16] * 16777216) / 65535);
	$key[14] = intval(($four - @$key[16] * 16777216 - @$key[15] * 65536) / 256);
	$key[13] = intval(($four - @$key[16] * 16777216 - @$key[15] * 65536 - @$key[14] * 256));
	
	$dst[1]  = $dst[1] ^ @$key[1]; $i=1;
	
	while ($i<16)
	{
		$i++; 
		$dst[$i] = @$dst[$i] ^ @$dst[$i-1] ^ @$key[$i];
	}
	
	$i=0;
	while ($i<16)
	{
		$i++;	
		if($dst[$i]==0)
		{
			$dst[$i] = 102;
		}
	}
	
	$encrypt = "0x"; 
	$i=0;
	while ($i<16)
	{
		$i++; 
		if($dst[$i] < 16) 
		{
			$encrypt = $encrypt . "0" . dechex($dst[$i]);
		} 
		else 
		{
			$encrypt = $encrypt . dechex($dst[$i]);
		}
	}
	
	return $encrypt;
}
adriahu is offline  
Old 05.08.2007, 19:45   #13
emanuel
Архивный участник
 
Join Date: May 2007
Posts: 86
Default

What is the difference between function on L2CP and this 2 functions ? :happy4:
emanuel is offline  
Old 05.08.2007, 19:54   #14
adriahu
Архивный участник
 
Join Date: Oct 2006
Posts: 47
Default

my function is resist for errors (max chars 16).
adriahu is offline  
Old 05.08.2007, 20:47   #15
supermamie
Архивный участник
 
Join Date: Jun 2007
Posts: 14
Default

Thank's a lot

It seems this works with numbers too
supermamie is offline  
Old 06.08.2007, 21:34   #16
Kenjiro
Архивный участник
 
Join Date: Apr 2006
Posts: 120
Default

Hmm, mine is tested with a-zA-Z0-9!@#$%^&*()-_=+[]{}\|;':",./<>? and working, and... why shouldn't? It is mathematically the same as l2asp version (but ASP was lowercasing letters which was a bit annoying).
Kenjiro is offline  
Old 07.08.2007, 09:15   #17
supermamie
Архивный участник
 
Join Date: Jun 2007
Posts: 14
Default

I really don't know, but every people on my server with numbers in their password had problem
supermamie is offline  
Old 07.08.2007, 19:53   #18
Kenjiro
Архивный участник
 
Join Date: Apr 2006
Posts: 120
Default

Which version are U using before? Mine and adriahu versions is essentially the same (minor coding styles and array offset).
Kenjiro is offline  
Old 11.08.2007, 15:35   #19
supermamie
Архивный участник
 
Join Date: Jun 2007
Posts: 14
Default

First I used some version found on this forum and the code in L2CP, then your's but with problems with numbers, and now, adriahu's one, without problems.
supermamie is offline  
Old 11.08.2007, 17:10   #20
Phantom2005
Архивный участник
 
Join Date: Aug 2005
Posts: 394
Default

I'd personally exchange:
Code:
	$nBytes = strlen($str);
	
	while ($i < $nBytes)
	{
		$i++; 
		$key[$i] = ord(substr($str, $i - 1, 1)); 
		$dst[$i] = $key[$i];
	}
for
Code:
	while ($i < 16) {
		$i++;
		$key[$i] = '';
		$dst[$i] = '';
		$key[$i] = ord(substr($str, $i - 1, 1));
		$dst[$i] = $key[$i];
	}
A password can not be bigger then 16 chars. ( quote l2cp: if(strlen($password) < 4 || strlen($password) > 16) { )
If you don't do this there will be $key's that will remain "undefined".
If you have error_reporting on E_ALL you will have a few warnings.
If you exchange that part with my code those warnings will be gone + will work fine.
Phantom2005 is offline  
Old 11.08.2007, 18:21   #21
Kenjiro
Архивный участник
 
Join Date: Apr 2006
Posts: 120
Default

Yes, you're right, all variables should be initialized before use, thus in my version is:
PHP Code:
$dst = $key = array ( 0 => 0, 1 => 0, 2 => 0, 3 => 0, 4 => 0, 5 => 0, 6 => 0, 7 => 0, 8 => 0, 9 => 0, 10 => 0, 11 => 0, 12 => 0, 13 => 0, 14 => 0, 15 => 0 );

for ( 
$i = 0; $i < strlen ( $plain ); $i++ ) {
  
$dst [ $i ] = $key [ $i ] = ord ( substr ( $plain, $i, 1 ) );
} 
Btw, $dst and $key variables is integers, not characters, thus this should be (for sake of correctness):
PHP Code:
$key[$i] = $dst[$i] = 0; 
Of course it'll work with $dst[$i] = '' because of dynamic typing in PHP, but you should have in mind that future version could have some another type management (maybe explicit type conversions?).
Kenjiro is offline  
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 16:56.