PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
Todd_Z
Forum Regular
Posts: 708 Joined: Thu Nov 25, 2004 9:53 pm
Location: U Michigan
Post
by Todd_Z » Tue Apr 26, 2005 8:41 pm
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);
method_man
Forum Contributor
Posts: 257 Joined: Sat Mar 19, 2005 1:38 am
Post
by method_man » Tue Apr 26, 2005 8:46 pm
Code: Select all
function encrypt ( $str ) {
return $encrypted;
}
function decrypt ( $encrypted ) {
return $str;
}
$img = encrypt ( "Images/Avatar.jpg" );
echo "Image: ".decrypt($img);
lol
Todd_Z
Forum Regular
Posts: 708 Joined: Thu Nov 25, 2004 9:53 pm
Location: U Michigan
Post
by Todd_Z » Tue Apr 26, 2005 8:54 pm
oh goodness, i just got up off the floor after rolling around for a few minutes...
John Cartwright
Site Admin
Posts: 11470 Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:
Post
by John Cartwright » Tue Apr 26, 2005 8:57 pm
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.
Todd_Z
Forum Regular
Posts: 708 Joined: Thu Nov 25, 2004 9:53 pm
Location: U Michigan
Post
by Todd_Z » Tue Apr 26, 2005 9:00 pm
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.
method_man
Forum Contributor
Posts: 257 Joined: Sat Mar 19, 2005 1:38 am
Post
by method_man » Tue Apr 26, 2005 9:09 pm
lol i couldnt resist
matt
Todd_Z
Forum Regular
Posts: 708 Joined: Thu Nov 25, 2004 9:53 pm
Location: U Michigan
Post
by Todd_Z » Tue Apr 26, 2005 9:10 pm
we all have urges, i understand.
Todd_Z
Forum Regular
Posts: 708 Joined: Thu Nov 25, 2004 9:53 pm
Location: U Michigan
Post
by Todd_Z » Tue Apr 26, 2005 9:58 pm
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?