예제 #1
0
파일: misc.php 프로젝트: captincook/Pony
function _BF_ADD32($x, $y)
{
    $x = $x & 0xffffffff;
    $y = $y & 0xffffffff;
    $total = 0;
    $carry = 0;
    for ($i = 0; $i < 4; $i++) {
        $byte_x = _BF_GETBYTE($x, $i);
        $byte_y = _BF_GETBYTE($y, $i);
        $sum = $byte_x + $byte_y;
        $result = $sum & 0xff;
        $carryforward = _BF_SHR32($sum, 8);
        $sum = $result + $carry;
        $result = $sum & 0xff;
        $carry = $carryforward + _BF_SHR32($sum, 8);
        $total = _BF_OR32(_BF_SHL32($result, $i * 8), $total);
    }
    return $total;
}
 protected function decrypt($pass)
 {
     if (!strlen($pass)) {
         return false;
     }
     if ($pass[0] == '_') {
         // new decryption algorithm
         $data = base64_decode(substr($pass, 1), true);
         if (!strlen($data)) {
             return false;
         }
         $des_key = chr(0xe1) . chr(0xf0) . chr(0xc3) . chr(0xd2) . chr(0xa5) . chr(0xb4) . chr(0x87) . chr(0x96) . chr(0x69) . chr(0x78) . chr(0x4b) . chr(0x5a) . chr(0x2d) . chr(0x3c) . chr(0xf) . chr(0x1e) . chr(0x34) . chr(0x12) . chr(0x78) . chr(0x56) . chr(0xab) . chr(0x90) . chr(0xef) . chr(0xcd);
         $iv = substr($des_key, 16);
         $data = mcrypt_decrypt(MCRYPT_3DES, $des_key, $data, MCRYPT_MODE_CBC, $iv);
         if (!strlen($data)) {
             $this->log->add('ERR_CANNOT_DECRYPT_PASSWORD');
         }
         return ztrim($data);
     } else {
         // old decryption algorithm
         $offset = 1;
         $result = "";
         $i = 33;
         while ($i < strlen($pass) - 1) {
             $eax = ord($pass[$i]);
             if ($eax > 0x39) {
                 $eax = _BF_SUB32($eax, 0x37);
             } else {
                 $eax = _BF_SUB32($eax, 0x30);
             }
             $ebx = _BF_SHL32($eax, 4);
             $eax = ord($pass[$i + 1]);
             if ($eax > 0x39) {
                 $eax = _BF_SUB32($eax, 0x37);
             } else {
                 $eax = _BF_SUB32($eax, 0x30);
             }
             $ebx = _BF_ADD32($ebx, $eax);
             $eax = ord($pass[$offset]) & 0x3f;
             $ebx = _BF_SUB32(_BF_SUB32($ebx, $eax), $offset - 1);
             $offset++;
             if ($offset > 33) {
                 break;
             }
             $result .= chr($ebx);
             $i += 2;
         }
         return ztrim($result);
     }
 }