chore (pyqdes): 合并代码仓库 x2

This commit is contained in:
helloplhm-qwq 2024-04-20 23:12:12 +08:00
parent 56a8c2d18c
commit bf16930c70

51
deps/pyqdes/main.cpp vendored
View File

@ -1,6 +1,6 @@
#include "des.cpp" #include "des.cpp"
#include <Python.h> #include <pybind11/pybind11.h>
#define PY_SSIZE_T_CLEAN
unsigned char KEY1[] = "!@#)(NHLiuy*$%^&"; unsigned char KEY1[] = "!@#)(NHLiuy*$%^&";
unsigned char KEY2[] = "123ZXC!@#)(*$%^&"; unsigned char KEY2[] = "123ZXC!@#)(*$%^&";
unsigned char KEY3[] = "!@#)(*$%^&abcDEF"; unsigned char KEY3[] = "!@#)(*$%^&abcDEF";
@ -30,38 +30,27 @@ void LyricDecode_(unsigned char *content, int len)
func_ddes(content, KEY3, len); func_ddes(content, KEY3, len);
} }
static PyObject* lyric_decode(PyObject* self, PyObject* args) { namespace py = pybind11;
const char* content;
int len;
// Parse arguments // 修改 LyricDecode 函数,接受和返回字节数组
if (!PyArg_ParseTuple(args, "s#", &content, &len)) { py::bytes LyricDecode(py::bytes input)
return NULL; {
} // 获取输入字节数组的指针和长度
const char *input_ptr = PyBytes_AsString(input.ptr());
Py_ssize_t input_len = PyBytes_Size(input.ptr());
// Call the C function // 复制输入数据以便修改
LyricDecode_((unsigned char*)content, len); std::vector<unsigned char> data(input_ptr, input_ptr + input_len);
// Return the result as bytes // 调用 LyricDecode 函数进行解密
return Py_BuildValue("y#", content, len); LyricDecode_(data.data(), data.size());
// 创建输出字节数组
py::bytes output(reinterpret_cast<const char *>(data.data()), data.size());
return output;
} }
// Method table PYBIND11_MODULE(qdes, m) {
static PyMethodDef module_methods[] = { m.def("LyricDecode", &LyricDecode, "Decrypt a string");
{"LyricDecode", lyric_decode, METH_VARARGS, "QRC Decrypt."},
{NULL, NULL, 0, NULL} /* Sentinel */
};
// Module initialization function
static struct PyModuleDef lyric_decoder_module = {
PyModuleDef_HEAD_INIT,
"qdes",
NULL,
-1,
module_methods
};
// Module initialization
PyMODINIT_FUNC PyInit_qdes(void) {
return PyModule_Create(&lyric_decoder_module);
} }