Simplest most encrypt/decrypt methods

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

Post Reply
User avatar
Todd_Z
Forum Regular
Posts: 708
Joined: Thu Nov 25, 2004 9:53 pm
Location: U Michigan

Simplest most encrypt/decrypt methods

Post 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);
method_man
Forum Contributor
Posts: 257
Joined: Sat Mar 19, 2005 1:38 am

lol

Post 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
User avatar
Todd_Z
Forum Regular
Posts: 708
Joined: Thu Nov 25, 2004 9:53 pm
Location: U Michigan

Post by Todd_Z »

oh goodness, i just got up off the floor after rolling around for a few minutes... :x
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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.
User avatar
Todd_Z
Forum Regular
Posts: 708
Joined: Thu Nov 25, 2004 9:53 pm
Location: U Michigan

Post 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.
method_man
Forum Contributor
Posts: 257
Joined: Sat Mar 19, 2005 1:38 am

lol

Post by method_man »

lol i couldnt resist :D

matt
User avatar
Todd_Z
Forum Regular
Posts: 708
Joined: Thu Nov 25, 2004 9:53 pm
Location: U Michigan

Post by Todd_Z »

we all have urges, i understand.
User avatar
Todd_Z
Forum Regular
Posts: 708
Joined: Thu Nov 25, 2004 9:53 pm
Location: U Michigan

Post 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?
Post Reply