function encrypt( $string )
{
$key = '&g1@8477Fg9*';
No offense intended to you sir... but why do you use a static key in this way instead of using mcrypt? Please forgive my naivete regarding encryption.
$result = '';
for( $i = 1; $i <= strlen( $string ); $i++ )
{
$char = substr( $string, $i - 1, 1 );
$keychar = substr( $key, ( $i % strlen( $key ) ) - 1, 1 );
$char = chr( ord( $char ) + ord( $keychar ) );
$result .= $char;
}
return $result;
}
function decrypt( $string )
{
$key = '&g1@8477Fg9*';
Similar question here. I know you would need the key for decryption, but again why not use mcrypt? Has it not been hammered out enough to your liking?
$result = '';
for( $i = 1; $i <= strlen( $string ); $i++ )
{
$char = substr( $string, $i - 1, 1 );
$keychar = substr( $key, ( $i % strlen( $key ) ) - 1, 1 );
$char = chr( ord( $char ) - ord( $keychar ) );
$result .= $char;
}
return $result;
}
--
Teach a person to fish...
Ask smart questions: http://www.catb.org/~esr/faqs/smart-questions.html
PHP Manual: http://www.php.net/manual/en/index.php
php-general archives: http://marc.theaimsgroup.com/?l=php-general&w=2