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?
looking for a simple encryption/decryption algorithm
Moderator: General Moderators
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
- AKA Panama Jack
- Forum Regular
- Posts: 878
- Joined: Mon Nov 14, 2005 4:21 pm
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;
}