![]() |
|
|
|
|
#1 |
|
Архивный участник
Join Date: Aug 2006
Posts: 5
|
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 |
|
|
|
|
#2 |
|
Архивный участник
Join Date: Nov 2006
Posts: 204
|
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;
}
|
|
|
|
|
#3 |
|
Архивный участник
Join Date: Apr 2006
Posts: 118
|
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); 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. |
|
|
|
|
#4 |
|
Архивный участник
Join Date: Apr 2006
Posts: 554
|
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? |
|
|
|
|
#5 |
|
Архивный участник
Join Date: Apr 2006
Posts: 118
|
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
|
|
|
|
|
#6 |
|
Архивный участник
Join Date: Apr 2006
Posts: 554
|
Has understood, good job.
thanks. |
|
|
|
|
#7 |
|
Архивный участник
Join Date: Jun 2007
Posts: 14
|
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
|
|
|
|
|
#8 |
|
Архивный участник
Join Date: Apr 2006
Posts: 120
|
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 );
}
PHP Code:
|
|
|
|
|
#9 |
|
Архивный участник
Join Date: Apr 2006
Posts: 554
|
Kenjiro, that's cool.
Big thanks, +1. I will test. |
|
|
|
|
#10 |
|
Архивный участник
Join Date: Jun 2007
Posts: 14
|
Just tested, and it works great!
thank you a lot! |
|
|
|
|
#11 |
|
Архивный участник
Join Date: Jun 2007
Posts: 14
|
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. |
|
|
|
|
#12 |
|
Архивный участник
Join Date: Oct 2006
Posts: 47
|
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;
}
|
|
|
|
|
#13 |
|
Архивный участник
Join Date: May 2007
Posts: 86
|
What is the difference between function on L2CP and this 2 functions ? :happy4:
|
|
|
|
|
#14 |
|
Архивный участник
Join Date: Oct 2006
Posts: 47
|
my function is resist for errors (max chars 16).
|
|
|
|
|
#15 |
|
Архивный участник
Join Date: Jun 2007
Posts: 14
|
Thank's a lot
![]() It seems this works with numbers too
|
|
|
|
|
#16 |
|
Архивный участник
Join Date: Apr 2006
Posts: 120
|
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).
|
|
|
|
|
#17 |
|
Архивный участник
Join Date: Jun 2007
Posts: 14
|
I really don't know, but every people on my server with numbers in their password had problem
|
|
|
|
|
#18 |
|
Архивный участник
Join Date: Apr 2006
Posts: 120
|
Which version are U using before? Mine and adriahu versions is essentially the same (minor coding styles and array offset).
|
|
|
|
|
#19 |
|
Архивный участник
Join Date: Jun 2007
Posts: 14
|
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.
|
|
|
|
|
#20 |
|
Архивный участник
Join Date: Aug 2005
Posts: 394
|
I'd personally exchange:
Code:
$nBytes = strlen($str);
while ($i < $nBytes)
{
$i++;
$key[$i] = ord(substr($str, $i - 1, 1));
$dst[$i] = $key[$i];
}
Code:
while ($i < 16) {
$i++;
$key[$i] = '';
$dst[$i] = '';
$key[$i] = ord(substr($str, $i - 1, 1));
$dst[$i] = $key[$i];
}
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. |
|
|
|
|
#21 |
|
Архивный участник
Join Date: Apr 2006
Posts: 120
|
Yes, you're right, all variables should be initialized before use, thus in my version is:
PHP Code:
PHP Code:
|
|
|
| Thread Tools | Search this Thread |
| Display Modes | |
|
|