[ACCEPTED]-how to decrypt the crypt("name")-php
You can't. From the documentation:
Note: There is no decrypt 2 function, since
crypt()
uses a one-way algorithm.
Reading 1 documentation helps ;)
crypt is one way hashing, you can't decrypt 3 it.
If you want to compare it against another 2 string you could crypt that too and then 1 compare the two crypted strings.
crypt — One-way string hashing
0
Since crypt() produces a hash decrypting 3 is not possible. If you need to guess the 2 original data ("name") you can use a combination 1 of a brute force algorithm and a huge dictionary.
I have find an example for mcrypt and create 3 the two functions, for text or for binary 2 files:
function MyDecrypt($input,$key){
/* Open module, and create IV */
$td = mcrypt_module_open('des', '', 'ecb', '');
$key = substr($key, 0, mcrypt_enc_get_key_size($td));
$iv_size = mcrypt_enc_get_iv_size($td);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
/* Initialize encryption handle */
if (mcrypt_generic_init($td, $key, $iv) != -1) {
/* 2 Reinitialize buffers for decryption */
mcrypt_generic_init($td, $key, $iv);
$p_t = mdecrypt_generic($td, $input);
return $p_t;
/* 3 Clean up */
mcrypt_generic_deinit($td);
mcrypt_module_close($td);
}
} // end function Decrypt()
function MyCrypt($input, $key){
/* Open module, and create IV */
$td = mcrypt_module_open('des', '', 'ecb', '');
$key = substr($key, 0, mcrypt_enc_get_key_size($td));
$iv_size = mcrypt_enc_get_iv_size($td);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
/* Initialize encryption handle */
if (mcrypt_generic_init($td, $key, $iv) != -1) {
/* 1 Encrypt data */
$c_t = mcrypt_generic($td, $input);
mcrypt_generic_deinit($td);
return $c_t;
/* 3 Clean up */
mcrypt_generic_deinit($td);
mcrypt_module_close($td);
}
}
For Example Crypt a string :
$original_text = "Hello world !";
$password = "abc123";
echo '<p>Original_text: '.$original_text.'</p>';
$crypted_text = MyCrypt($original_text,$password);
echo '<p>Crypted_text: '.$crypted_text.'</p>';
$decrypted_text= MyDecrypt($crypted_text,$password);
echo '<p>Decrypted_text: '.$decrypted_text.'</p>';
echo '<p>And if I try with a wrong password?</p>';
$wrong_decrypted_text= MyDecrypt($crypted_text,"wrong_pw");
echo '<p>Decrypted with wrong password: '.$wrong_decrypted_text.'</p>';
I hope 1 helpful
You can't truly decrypt it, because there 9 are (infinitely) many strings such that 8 crypt($input) == crypt("name")
-- but you can, via brute-force trial-and-error, find 7 some of those strings.
If you know or suspect 6 that the original string is a short dictionary 5 word, and you find a short dictionary word 4 that produces the same output, chances are 3 you have "decrypted" the original 2 string.
md5 and many weaker hash functions are 1 attacked in this way routinely.
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.