Re: Data Enryption

From: Date: Wed, 12 Jan 2005 15:51:31 +0000
Subject: Re: Data Enryption
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-206202@lists.php.net to get a copy of this message
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

« previous php.general (#206202) next »