我想做一个函数,可以返回一个字符串值。但是我在几天内偶然发现了这个问题,无法单独解决这个错误。所以我需要你的建议和提示。我正在使用 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;
}
而蟒蛇是:
from ctypes import *
d = CDLL('jh.dll')
a=d.jh('this is message by hash jh function')
print a
这是一个更新代码,但仍然没有得到预期值。当我尝试从 python 调用时,返回的值是整数“9968784”。任何帮助将不胜感激,谢谢..