-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpython.c
37 lines (29 loc) · 871 Bytes
/
python.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#ifdef __APPLE__
#include <Python/Python.h>
#else
#include <Python.h>
#endif
#include "include/fjk.h"
PyObject* _py_fjk_wrap(PyObject *args, fjk_algo method) {
const char *s;
if (!PyArg_ParseTuple(args, "s", &s))
return NULL;
return Py_BuildValue("s#", method(s, strlen(s)), strlen(s));
}
static PyObject* py_fjk_encrypt(PyObject *self, PyObject *args) {
return _py_fjk_wrap(args, fjk_encrypt);
}
static PyObject* py_fjk_decrypt(PyObject *self, PyObject *args) {
return _py_fjk_wrap(args, fjk_decrypt);
}
static PyMethodDef FjkMethods[] = {
{"encrypt", py_fjk_encrypt, METH_VARARGS, "Encrypt string."},
{"decrypt", py_fjk_decrypt, METH_VARARGS, "Decrypt string."},
{NULL, NULL, 0, NULL} /* Sentinel */
};
PyMODINIT_FUNC initfjk(void) {
PyObject *m;
m = Py_InitModule("fjk", FjkMethods);
if (m == NULL)
return;
}