I have a cryptography project I am working on, and the module I am using is Python only so I can't use it in C++. I would like to compile the Python code into a .pyc file (a compiled python file) and use this in my C++ project.
I would like to call these functions in my C++ code as I please and have it execute smoothly. How can I go about doing this? If the method I am desiring isn't feasible, how can I achieve this with an alternate method?
Desired result: I use the .pyc file and its functions seamlessly in my C++ code. If my question sucks, please tell me why!
Reproducible Python Code (It will compile the python code for you when it runs.)
import hashlib
import py_compile
py_compile.compile("crypto.py")
def generate_keys():
public_key = "Please help me".encode("utf-8")
alphanumeric_address = hashlib.sha256(public_key).hexdigest()
return public_key, alphanumeric_address
Sample C++ Code:
#include <iostream>
// Do whatever you need to import the function in here.
int main ()
{
std::string alphanumeric_address = /* Import Python Function here as a variable, calling the
alphanumeric_address specified in the generate_keys() function */
std::cout << alphanumeric_address << std::endl;
}