Jump to content

I cant figure out how to use this one function??


jdock1

Recommended Posts

Ok, so there are two functions, one encrypts data, the other one must decrypt. But I do not know how to implement it to decrypt.

 

I need to know how to use the second function (number_decrypt). I need it so I enter the encrypted string into a text field and it outputs the decypted string.

 

I dont need the html, I just dont understand how to implement it.

 

 

Can someone look at this for me and possibly tell me how I could achieve this?

 

Heres the code:

function number_encrypt($plain)
{
	mt_srand ((double) microtime() * 1000000);
	$password = '';

	for ($i=0; $i<10; $i++) {
	  $password .= rand(1,1000);
	}

	$salt = substr(md5($password), 0, 2);

	$password = md5($salt . $plain) . ':' . $salt;

	return $password;
}

function number_decrypt($encrypted,$plain)
{
	$stack = explode(':', $encrypted);
	if (sizeof($stack) != 2) return false;

	if (md5($stack[1] . $plain) == $stack[0]) 
	{
		return true;
	}

	return false;
}

 

Thanks!

 

number_decrypt() just tests if the supplied value in $plain is the value that produced the given $encrypted (hashed) value.

 

Sadly, those functions, despite the unfortunate names given them, neither encrypt or decrypt anything because encryption/decryption is a two way process. Those functions are using a md5 hash/checksum and it is a one way process. Once you have the hashed value, the only thing you can do is test if a value that is hashed using the same algorithm matches.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.