gpt4 book ai didi

python - 如何将数组转换为字符,以便我可以从c中的函数返回该字符值。然后,在Python中调用它。

转载 作者:行者123 更新时间:2023-11-30 15:58:04 27 4
gpt4 key购买 nike

我想做一个函数,可以返回一个字符串值。但我在几天内偶然发现了这个问题,无法单独解决这个错误。所以我需要你的建议和提示。我使用的是 Hash jh sha3 2010 候选函数。这是代码:

anyway this an update code, but I still dont get expected value to get this function called from Python Language. the returned value is "9976864". Anymore helps?

#include <stdio.h>
#include "jh_ansi_opt32.h"
#include <time.h>
#include <stdlib.h>

char* jh(char *input)
{
BitSequence output[512];
char *iData;
char* msg;

int dInt;

msg= (char*)malloc(sizeof(output));
if(!msg){
return 1;
}

memset(output,0,sizeof(output));

iData = input;
printf("[+] data is %s\n", iData);
dInt = strlen(iData);
BitSequence data[dInt];

memset(data,0, sizeof(data));
strncpy(data,iData,dInt);
DataLength dLen =dInt;
HashJh(512, data,dLen,output);
//printf("\n[+] resulted hash is ");

int k;
for (k=0;k<sizeof(output);k++){
msg[k]= output[k];
}
if (msg) return msg;
free(msg);
return 0;
}

Python 是:

from ctypes import *
d = CDLL('jh.dll')
a=d.jh('this is message by hash jh function')
print a

这是一个更新代码,但仍然没有得到预期的值。当我尝试从 python 调用时,返回的值是整数“9968784”。任何帮助将不胜感激,谢谢..

最佳答案

if (!(BitSequence *)malloc(sizeof(output)))
exit(EXIT_FAILURE);

这没有任何作用。其次,您递增 msg然后返回它。第三,您似乎从未取消引用 msg,您只是递增它。

关于python - 如何将数组转换为字符,以便我可以从c中的函数返回该字符值。然后,在Python中调用它。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10050078/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com