// xxtea_Encrypt.cpp : 定义控制台应用程序的入口点。 // #include "xxtea.h" #include "Python.h" PyObject* xxtea_encrypt(PyObject* self, PyObject* args) { unsigned char *data = NULL; unsigned char *key = NULL; unsigned int dataLen = 0; unsigned int keyLen = 0; unsigned int retLen = 0; if (! PyArg_ParseTuple(args, "s#s#", &data,&dataLen,&key,&keyLen)) return NULL; unsigned char * encrypt = xxtea_encrypt(data,dataLen,key,keyLen,&retLen); return Py_BuildValue("s#",encrypt,retLen); } PyObject* xxtea_decrypt(PyObject* self, PyObject* args) { unsigned char *data = NULL; unsigned char *key = NULL; unsigned int dataLen = 0; unsigned int keyLen = 0; unsigned int retLen = 0; if (! PyArg_ParseTuple(args, "s#s#", &data,&dataLen,&key,&keyLen)) return NULL; unsigned char * decrypt = xxtea_decrypt(data,dataLen,key,keyLen,&retLen); return Py_BuildValue("s#",decrypt,retLen); } static PyMethodDef xxteaMethods[] = { {"encrypt", xxtea_encrypt, METH_VARARGS, "xxteaEncrypt"}, {"decrypt", xxtea_decrypt, METH_VARARGS, "xxteaDecrypt"}, {NULL, NULL} }; void initxxteaModule() { PyObject* m; m = Py_InitModule("xxteaModule", xxteaMethods); }
from distutils.core import setup, Extension MOD = 'xxteaModule' setup (name = MOD,ext_modules = [Extension(name=MOD, sources = ['xxtea_Encrypt.cpp','xxtea.cpp'])])
import xxteaModule def EncodeWithXxteaModule(filePath,key,signment): all_the_text = ReadFile(filePath) if all_the_text[:len(signment)] == signment : return #bak lua BakFile(filePath,all_the_text) encrypt = xxteaModule.encrypt(all_the_text,key) signment = signment + encrypt WriteFile(filePath,signment)