Някой може ли да ми помогне да превърна това в php скрипт?

Dido_net

Registered
:shock: :shock:


Нещо се пробвах.. ама не става номера.. О_О
Ето това са операторите:


=
Assignment. e.g. $var = 5 (assigns the number 5 to $var)
+=
Addition assignment. e.g. $var += 1 (adds 1 to $var)
-=
Subtraction assignment.
*=
Multiplication assignment.
/=
Division assignment.
&=
Concatenation assignment. e.g. $var = "one", and then $var &= 10 ($var now equals "one10")



+ Adds two numbers. e.g. 10 + 20 (equals 30)
- Subtracts two numbers. e.g. 20 - 10 (equals 10)
* Multiplies two numbers. e.g. 20 * 10 (equals 200)
/ Divides two numbers. e.g. 20 / 10 (equals 2)
& Concatenates/joins two strings. e.g. "one" & 10 (equals "one10")
^ Raises a number to the power. e.g. 2 ^ 4 (equals 16)



= Tests if two values are equal (case insensitive if used with strings). e.g. If $var= 5 Then (true if $var equals 5)
== Tests if two values are equal (case sensitive if used with strings)
<> Test if two values are not equal.
> Tests if the first value is greater than the second.
>= Tests if the first value is greater than or equal to the second.
< Tests if the first value is less than the second.
<= Tests if the first value is less than or equal to the second.



AND Logical AND operation. e.g. If $var = 5 AND $var2 > 6 Then (true if $var equals 5 and $var2 is greater than 6)
OR Logical OR operation. e.g. If $var = 5 OR $var2 > 6 Then (true if $var equals 5 or $var2 is greater than 6)
NOT Logical NOT operation. e.g. NOT 1 (equals 0)


Ето го скрипта...


Код:
Func _StringEncrypt($i_Encrypt, $s_EncryptText, $s_EncryptPassword, $i_EncryptLevel = 1)
	If $i_Encrypt <> 0 And $i_Encrypt <> 1 Then
		SetError(1)
		Return ''
	ElseIf $s_EncryptText = '' Or $s_EncryptPassword = '' Then
		SetError(1)
		Return ''
	Else
		If Number($i_EncryptLevel) <= 0 Or Int($i_EncryptLevel) <> $i_EncryptLevel Then $i_EncryptLevel = 1
		Local $v_EncryptModified
		Local $i_EncryptCountH
		Local $i_EncryptCountG
		Local $v_EncryptSwap
		Local $av_EncryptBox[256][2]
		Local $i_EncryptCountA
		Local $i_EncryptCountB
		Local $i_EncryptCountC
		Local $i_EncryptCountD
		Local $i_EncryptCountE
		Local $v_EncryptCipher
		Local $v_EncryptCipherBy
		If $i_Encrypt = 1 Then
			For $i_EncryptCountF = 0 To $i_EncryptLevel Step 1
				$i_EncryptCountG = ''
				$i_EncryptCountH = ''
				$v_EncryptModified = ''
				For $i_EncryptCountG = 1 To StringLen($s_EncryptText)
					If $i_EncryptCountH = StringLen($s_EncryptPassword) Then
						$i_EncryptCountH = 1
					Else
						$i_EncryptCountH += 1
					EndIf
					$v_EncryptModified = $v_EncryptModified & Chr(BitXOR(Asc(StringMid($s_EncryptText, $i_EncryptCountG, 1)), Asc(StringMid($s_EncryptPassword, $i_EncryptCountH, 1)), 255))
				Next
				$s_EncryptText = $v_EncryptModified
				$i_EncryptCountA = ''
				$i_EncryptCountB = 0
				$i_EncryptCountC = ''
				$i_EncryptCountD = ''
				$i_EncryptCountE = ''
				$v_EncryptCipherBy = ''
				$v_EncryptCipher = ''
				$v_EncryptSwap = ''
				$av_EncryptBox = ''
				Local $av_EncryptBox[256][2]
				For $i_EncryptCountA = 0 To 255
					$av_EncryptBox[$i_EncryptCountA][1] = Asc(StringMid($s_EncryptPassword, Mod($i_EncryptCountA, StringLen($s_EncryptPassword)) + 1, 1))
					$av_EncryptBox[$i_EncryptCountA][0] = $i_EncryptCountA
				Next
				For $i_EncryptCountA = 0 To 255
					$i_EncryptCountB = Mod(($i_EncryptCountB + $av_EncryptBox[$i_EncryptCountA][0] + $av_EncryptBox[$i_EncryptCountA][1]), 256)
					$v_EncryptSwap = $av_EncryptBox[$i_EncryptCountA][0]
					$av_EncryptBox[$i_EncryptCountA][0] = $av_EncryptBox[$i_EncryptCountB][0]
					$av_EncryptBox[$i_EncryptCountB][0] = $v_EncryptSwap
				Next
				For $i_EncryptCountA = 1 To StringLen($s_EncryptText)
					$i_EncryptCountC = Mod(($i_EncryptCountC + 1), 256)
					$i_EncryptCountD = Mod(($i_EncryptCountD + $av_EncryptBox[$i_EncryptCountC][0]), 256)
					$i_EncryptCountE = $av_EncryptBox[Mod(($av_EncryptBox[$i_EncryptCountC][0] + $av_EncryptBox[$i_EncryptCountD][0]), 256) ][0]
					$v_EncryptCipherBy = BitXOR(Asc(StringMid($s_EncryptText, $i_EncryptCountA, 1)), $i_EncryptCountE)
					$v_EncryptCipher &= Hex($v_EncryptCipherBy, 2)
				Next
				$s_EncryptText = $v_EncryptCipher
			Next
		Else
			For $i_EncryptCountF = 0 To $i_EncryptLevel Step 1
				$i_EncryptCountB = 0
				$i_EncryptCountC = ''
				$i_EncryptCountD = ''
				$i_EncryptCountE = ''
				$v_EncryptCipherBy = ''
				$v_EncryptCipher = ''
				$v_EncryptSwap = ''
				$av_EncryptBox = ''
				Local $av_EncryptBox[256][2]
				For $i_EncryptCountA = 0 To 255
					$av_EncryptBox[$i_EncryptCountA][1] = Asc(StringMid($s_EncryptPassword, Mod($i_EncryptCountA, StringLen($s_EncryptPassword)) + 1, 1))
					$av_EncryptBox[$i_EncryptCountA][0] = $i_EncryptCountA
				Next
				For $i_EncryptCountA = 0 To 255
					$i_EncryptCountB = Mod(($i_EncryptCountB + $av_EncryptBox[$i_EncryptCountA][0] + $av_EncryptBox[$i_EncryptCountA][1]), 256)
					$v_EncryptSwap = $av_EncryptBox[$i_EncryptCountA][0]
					$av_EncryptBox[$i_EncryptCountA][0] = $av_EncryptBox[$i_EncryptCountB][0]
					$av_EncryptBox[$i_EncryptCountB][0] = $v_EncryptSwap
				Next
				For $i_EncryptCountA = 1 To StringLen($s_EncryptText) Step 2
					$i_EncryptCountC = Mod(($i_EncryptCountC + 1), 256)
					$i_EncryptCountD = Mod(($i_EncryptCountD + $av_EncryptBox[$i_EncryptCountC][0]), 256)
					$i_EncryptCountE = $av_EncryptBox[Mod(($av_EncryptBox[$i_EncryptCountC][0] + $av_EncryptBox[$i_EncryptCountD][0]), 256) ][0]
					$v_EncryptCipherBy = BitXOR(Dec(StringMid($s_EncryptText, $i_EncryptCountA, 2)), $i_EncryptCountE)
					$v_EncryptCipher = $v_EncryptCipher & Chr($v_EncryptCipherBy)
				Next
				$s_EncryptText = $v_EncryptCipher
				$i_EncryptCountG = ''
				$i_EncryptCountH = ''
				$v_EncryptModified = ''
				For $i_EncryptCountG = 1 To StringLen($s_EncryptText)
					If $i_EncryptCountH = StringLen($s_EncryptPassword) Then
						$i_EncryptCountH = 1
					Else
						$i_EncryptCountH += 1
					EndIf
					$v_EncryptModified &= Chr(BitXOR(Asc(StringMid($s_EncryptText, $i_EncryptCountG, 1)), Asc(StringMid($s_EncryptPassword, $i_EncryptCountH, 1)), 255))
				Next
				$s_EncryptText = $v_EncryptModified
			Next
		EndIf
		Return $s_EncryptText
	EndIf
EndFunc   ;==>_StringEncrypt
 
Може би никой няма да успее, затова кажи какво прави горният код за да помислим всички и да ти кажем PHP-то.
 
трябва ми вид закодиране... да го пращам някъде и там да го отключвам... но да ами трябва "код" за да го отключа... в пхп май няма такава функция. :idea:
 
Dido_net каза:
трябва ми вид закодиране... да го пращам някъде и там да го отключвам... но да ами трябва "код" за да го отключа... в пхп май няма такава функция. :idea:

Е да ама в MySQL има: ENCODE & DECODE
$rez = mysql_query("SELECT ENCODE("YourString","YourKey")",$dblink);
$red = mysql_fetch_row($rez);
Сега пращаш $red[0] (това е кодирания текст) а е ключа за декодиране ("YourKey") отсрещния трябва да го знае, за да ползва DECODE.

8)
 
На мен ми трябва за променлива, не за запис в DB..
а трябва и клиента и програмата да може да кодират/разкодират това което получават/пращат.
 
Не съм сигурен, че разбирам, затова само насоки:

http://bg2.php.net/manual/en/function.serialize.php

http://bg2.php.net/manual/en/function.gzencode.php

Дано не те обърквам.
Успех!
 
начин 1:

Код:
<?php

  function bytexor($a,$b,$l)
  {
    $c="";
    for($i=0;$i<$l;$i++) {
      $c.=$a{$i}^$b{$i};
    }
    return($c);
  }

  function binmd5($val)
  {
    return(pack("H*",md5($val)));
  }

  function decrypt_md5($msg,$heslo)
  {
    $key=$heslo;$sifra="";
    $key1=binmd5($key);
    while($msg) {
      $m=substr($msg,0,16);
      $msg=substr($msg,16);
      $sifra.=$m=bytexor($m,$key1,16);
      $key1=binmd5($key.$key1.$m);
    }
    echo "\n";
    return($sifra);
  }

  function crypt_md5($msg,$heslo)
  {
    $key=$heslo;$sifra="";
    $key1=binmd5($key);
    while($msg) {
      $m=substr($msg,0,16);
      $msg=substr($msg,16);
      $sifra.=bytexor($m,$key1,16);
      $key1=binmd5($key.$key1.$m);
    }
    echo "\n";
    return($sifra);
  }

// Example of usage...

$message = "This is a very long message, but it is very secret and important
and we need to keep the contents hidden from nasty people who might want to steal it.";

$key = "secret key";

$crypted = crypt_md5($message, $key);
echo "Encoded = $crypted<BR>"; // returns ��=� ���`��<�H ���{.�1�{��ɑђJ�V�+߳j�e�

$uncrypted = decrypt_md5($crypted, $key);
echo "Unencoded = $uncrypted"; // returns This is a very long message (etc)

?>

начин 2:

Код:
<?php

function get_rnd_iv($iv_len)
{
    $iv = '';
    while ($iv_len-- > 0) {
        $iv .= chr(mt_rand() & 0xff);
    }
    return $iv;
}

function md5_encrypt($plain_text, $password, $iv_len = 16)
{
    $plain_text .= "\x13";
    $n = strlen($plain_text);
    if ($n % 16) $plain_text .= str_repeat("\0", 16 - ($n % 16));
    $i = 0;
    $enc_text = get_rnd_iv($iv_len);
    $iv = substr($password ^ $enc_text, 0, 512);
    while ($i < $n) {
        $block = substr($plain_text, $i, 16) ^ pack('H*', md5($iv));
        $enc_text .= $block;
        $iv = substr($block . $iv, 0, 512) ^ $password;
        $i += 16;
    }
    return base64_encode($enc_text);
}

function md5_decrypt($enc_text, $password, $iv_len = 16)
{
    $enc_text = base64_decode($enc_text);
    $n = strlen($enc_text);
    $i = $iv_len;
    $plain_text = '';
    $iv = substr($password ^ substr($enc_text, 0, $iv_len), 0, 512);
    while ($i < $n) {
        $block = substr($enc_text, $i, 16);
        $plain_text .= $block ^ pack('H*', md5($iv));
        $iv = substr($block . $iv, 0, 512) ^ $password;
        $i += 16;
    }
    return preg_replace('/\\x13\\x00*$/', '', $plain_text);
}

/******************************************/
$plain_text = 'very secret string';
$password = 'very secret password';
echo "plain text is: [${plain_text}]<br />\n";
echo "password is: [${password}]<br />\n";

$enc_text = md5_encrypt($plain_text, $password);
echo "encrypted text is: [${enc_text}]<br />\n";

$plain_text2 = md5_decrypt($enc_text, $password);
echo "decrypted text is: [${plain_text2}]<br />\n";

?>

Взети са от коментарите на http://bg2.php.net/manual/en/function.md5.php
 
в случая някой от скриптовете съвпада ли с горния... или трябва да правя UDF за програмата и UDF за php кода..? :roll:
 
Не знам дали съвпада, но теб ти трябва за кодиране.декодиране на стринг със зададаен от теб ключ, "начин 1: " е точно това, кодира и разкодира със зададен от теб ключ.
 

Back
Горе