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!

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.