note 72036 added to ref.mcrypt
| From: | tokai at binaryriot dot org | Date: | Sat, 30 Dec 2006 03:22:12 +0000 |
| Subject: | note 72036 added to ref.mcrypt | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-121055@lists.php.net to get a copy of this message | ||
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;
}
?>
----
Server IP: 66.163.161.117
Probable Submitter: 84.184.67.182
----
Manual Page -- http://www.php.net/manual/en/ref.mcrypt.php
Edit -- https://master.php.net/note/edit/72036
Del: integrated -- https://master.php.net/note/delete/72036/integrated
Del: useless -- https://master.php.net/note/delete/72036/useless
Del: bad code -- https://master.php.net/note/delete/72036/bad+code
Del: spam -- https://master.php.net/note/delete/72036/spam
Del: non-english -- https://master.php.net/note/delete/72036/non-english
Del: in docs -- https://master.php.net/note/delete/72036/in+docs
Del: other reasons-- https://master.php.net/note/delete/72036
Reject -- https://master.php.net/note/reject/72036
Search -- https://master.php.net/manage/user-notes.php