0

I have a Python program for some application. And I have a C program for encrypting a string. The python program generates a string and I want to use the C program to encrypt it. I read a lot about interfacing between C and Python and it does not seem to work. If anyone has any suggestions will be helpful.

#Python 
a="abcdefg" #Need to encrypt this
encrypted_a=encrypt_func(a)#This function is implemented in C code
//C code
#include<gmp.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
char* encrypt_func(char* a)//I want to input the string a="abcdefg" from python here 
{
char encrypted_string[20];
//do something
return encrypted_string;
}
Arnab Ghosh
  • 113
  • 7
  • 1
    You can send to the C program via a command-line argument or a pipe. The C program can send the result back through a pipe. Look at the Python `subprocess` module to see how to run the C program. – Barmar Jul 22 '21 at 16:33
  • 1
    The C program needs a `main()` function. – Barmar Jul 22 '21 at 16:33
  • 1
    You could also use Python's CFFI module https://pypi.org/project/cffi/ – Barmar Jul 22 '21 at 16:36

0 Answers0