Page 1 of 1
Simplest most encrypt/decrypt methods
Posted: Tue Apr 26, 2005 8:41 pm
by Todd_Z
Ready... heres a.... *contest*
I want to fill in these lines in as few lines as possible.
Code: Select all
function encrypt ( $str ) {
....
....
return $encrypted;
}
function decrypt ( $encrypted ) {
....
....
return $str;
}
$img = encrypt ( "Images/Avatar.jpg" );
echo "Image: ".decrypt($img);
lol
Posted: Tue Apr 26, 2005 8:46 pm
by method_man
Code: Select all
function encrypt ( $str ) {
return $encrypted;
}
function decrypt ( $encrypted ) {
return $str;
}
$img = encrypt ( "Images/Avatar.jpg" );
echo "Image: ".decrypt($img);
lol
Posted: Tue Apr 26, 2005 8:54 pm
by Todd_Z
oh goodness, i just got up off the floor after rolling around for a few minutes...

Posted: Tue Apr 26, 2005 8:57 pm
by John Cartwright
You do understand if you are wanting to hash something, securely for that matter you should not be able to easily retrieve the hashed value.
Posted: Tue Apr 26, 2005 9:00 pm
by Todd_Z
I just want to be able to decrypt and encrypt a string in as few lines as possible, i don't need anything super secure, just so that the lay-surfer can't copy and paste the url so that they can see the un-watermarked image.
lol
Posted: Tue Apr 26, 2005 9:09 pm
by method_man
lol i couldnt resist
matt
Posted: Tue Apr 26, 2005 9:10 pm
by Todd_Z
we all have urges, i understand.
Posted: Tue Apr 26, 2005 9:58 pm
by Todd_Z
I *may* have answered my own problems:
Code: Select all
$key = "*********";
$alg = MCRYPT_RIJNDAEL_128;
$mode = MCRYPT_MODE_CBC;
$iv = mcrypt_create_iv(mcrypt_get_iv_size($alg, MCRYPT_MODE_ECB), MCRYPT_RAND );
function encrypt ( $str ) {
$encrypted = mcrypt_encrypt( $GLOBALS["alg"], $GLOBALS["key"], $str, $GLOBALS["mode"], $GLOBALS["iv"] );
return $encrypted;
}
function decrypt ( $str ) {
$decrypted = mcrypt_decrypt( $GLOBALS["alg"], $GLOBALS["key"], $str, $GLOBALS["mode"], $GLOBALS["iv"] );
return trim( $decrypted );
}
Is that as compact as I can go?