looking for a simple encryption/decryption algorithm

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
jasongr
Forum Contributor
Posts: 206
Joined: Tue Jul 27, 2004 6:19 am

looking for a simple encryption/decryption algorithm

Post by jasongr »

Hi

I am looking for an alogrithm that will allow me to perform encryption/decryption
based on a hidden key.
I am preferring one that comes built in in PHP and not one that I need to start including
extensions for

any suggestions?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

jasongr
Forum Contributor
Posts: 206
Joined: Tue Jul 27, 2004 6:19 am

Post by jasongr »

Hi d11wtq

thanks for the reply, however, mcrypt requires re-compiling PHP with --with-mcrypt[=DIR] parameter

I am looking for a solution that doesn't require any compilation. Is there such?
User avatar
AKA Panama Jack
Forum Regular
Posts: 878
Joined: Mon Nov 14, 2005 4:21 pm

Post by AKA Panama Jack »

Here you go...

Code: Select all

define ("OrdKey","Make this key anything you want."); 

function ord_crypt_encode($data) {
	$result = '';
	for($i=0; $i<strlen($data); $i++) {
		$char = substr($data, $i, 1);
		$keychar = substr(OrdKey, ($i % strlen(OrdKey))-1, 1);
		$char = chr(ord($char)+ord($keychar));
		$result.=$char;
	}
	return bin2hex($result); 
}

function ord_crypt_decode($data) {
	$result = '';
	$data =  @pack("H" . strlen($data), $data); 
	for($i=0; $i<strlen($data); $i++) {
		$char = substr($data, $i, 1);
		$keychar = substr(OrdKey, ($i % strlen(OrdKey))-1, 1);
		$char = chr(ord($char)-ord($keychar));
		$result.=$char;
	}
	return $result;
}
redmonkey
Forum Regular
Posts: 836
Joined: Thu Dec 18, 2003 3:58 pm

Post by redmonkey »

I'm not sure there is much else (if anything) built into PHP if mcrypt isn't an option. In which case i'd say RC4, it's relatively secure and relatively light weight.
Post Reply