function text_decrypt($s, $key = false)
{
    global $blowfish;
    if (strlen($s) == 0) {
        return $s;
    }
    # Parse crypted data
    $type = cw_get_crypt_type($s);
    if ($type === false) {
        $type = "N";
        $crc32 = false;
    } elseif (substr($s, 1, 1) == '-') {
        $crc32 = true;
        $s = substr($s, 2);
    } else {
        $crc32 = substr($s, 1, 8);
        $s = substr($s, 9);
    }
    # Blowfish
    if ($type == 'B' || $type == 'C') {
        if ($key === false) {
            $key = cw_get_crypt_key($type);
        }
        if (!$blowfish) {
            cw_log_flag("log_decrypt_errors", "DECRYPT", "The Blowfish service object is missing", true);
            return false;
        } elseif (empty($key)) {
            cw_log_flag("log_decrypt_errors", "DECRYPT", "The key for the selected type ('" . $type . "') of encryption is missing", true);
            return false;
        }
        $result = trim(cw_bf_decrypt($s, $key));
    } elseif ($type == 'N') {
        # Non-encrypted
        $result = $s;
    }
    # CRC32 check
    if ($crc32 === true) {
        # Inner CRC32
        $crc32 = substr($result, -8);
        $result = substr($result, 0, -8);
        if (cw_crc32(md5($result)) != $crc32) {
            $result = NULL;
        }
    } elseif ($crc32 !== false) {
        # Outer CRC32
        if (cw_crc32($result) != $crc32) {
            $result = NULL;
        }
    }
    return $result;
}
function cw_bf_asc($array, $key)
{
    global $blowfish;
    $len = count($array);
    $return = "";
    for ($i = 1; $i < $len; $i++) {
        $return .= $blowfish->int2asc($array[$i]);
    }
    $return = cw_bf_decrypt($return, $key);
    if (crc32($return) != (int) $array[0]) {
        return false;
    }
    return $return;
}