note 72036 deleted from ref.mcrypt by didou

From: Date: Sat, 30 Dec 2006 04:01:06 +0000
Subject: note 72036 deleted from ref.mcrypt by didou
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-121072@lists.php.net to get a copy of this message
Note Submitter: tokai at binaryriot dot org Reason: useless ---- Since the simple encrypt() / decrypt() functions from this page actually could be useful for some nifty obsification I repost them with some improvements. I didn't benchmarked them, but they should be a lot faster now. ;-) <?php define('MAGIC', 'your magic default key/ string here'); /** * encrypt() * * @param string $s string to encrypt * @param string $key optional key * @return string */ function encrypt($s, $key = MAGIC) { $encrypted = ''; $slen = strlen($s); $klen = strlen($key); for($i=0; $i < $slen; $i++) { $sc = ord($s[$i]); $kc = ord($key[$i % $klen]); $encrypted .= chr($sc+$kc); } return $encrypted; } /** * decrypt() * Opposite to lapislazuli_encrypt. * * @param string $s string to decrypt * @param string $key optional key (must be same as for encrypt) * @return string */ function decrypt($s, $key = MAGIC) { $decrypted = ''; $slen = strlen($s); $klen = strlen($key); for($i=0; $i < $slen; $i++) { $sc = ord($s[$i]); $kc = ord($key[$i % $klen]); $decrypted .= chr($sc-$kc); } return $decrypted; } ?>

« previous php.notes (#121072) next »