注册 登录
编程论坛 VC++/MFC

听闻论坛里有许多大神。小女子过来凑热闹啦。。。。

ljh8888 发布于 2013-05-04 13:22, 1649 次点击
error C2665: 'PowerMod' : none of the 5 overloads can convert parameter 1 from type 'int'
能帮我分析一下这个错误吗??
21 回复
#2
ljh88882013-05-04 13:24
求vc++、openssl、ntl高手一枚啊、、、感激不尽啊
#3
azzbcc2013-05-04 22:04
木有代码。。。

谷歌翻译如下:

PowerMod 5 个重载中没有参数类型为 int的重载
#4
ljh88882013-05-05 18:29
回复 3楼 azzbcc
    for (i=0;i<32;i++)//进行合并得到变换后的密文
    {
        m[i]=R[i];
        m[i+32]=L[i];
    }
    for (i=0;i<64;i++)
    b[i]=m[i];
    for (i=0;i<64;i++)//进行IP逆变换,得到最终密文
    m[i]=b[IP1[i]-1];
    cout<<"密文二进制流=";
    for (i=0;i<64;i++)
    cout<<m[i];
    cout<<endl;

//………………参数r的计算………………^o^
    ZZ m_r,c_p,c;
    c=to_ZZ(m_c);
    c_p=PowerMod(c,1,m_p);
    cout<<c_p<<endl;
#5
ljh88882013-05-05 18:30
回复 3楼 azzbcc
诸多代码不能一一贴出。求分析
#6
azzbcc2013-05-06 06:50
你贴的代码,只有三行与错误相关

ZZ m_r,c_p,c;
c=to_ZZ(m_c);
c_p=PowerMod(c,1,m_p);

ZZ是什么类型?
m_p又是哪类变量?
我,,,

这怎么分析啊
#7
azzbcc2013-05-06 06:51
这么说吧,我先假设你的m_p是 char型变量

找一找你的代码中有没有定义这个函数

ZZ PowerMod(ZZ, int, char);
#8
ljh88882013-05-06 10:15
回复 7楼 azzbcc
程序代码:
    int bit=1024;
    unsigned char seeds[]="myseed";
    char errbuf[256];
    DSA *myDSA;            //定义DSA结构体
    myDSA = DSA_new();
    myDSA = DSA_generate_parameters(bit, seeds, 6, NULL, NULL, NULL, NULL);   //生成密钥参数
    if (myDSA == NULL)
    {   
        unsigned long errorcode = ERR_get_error();
        ERR_error_string(errorcode, errbuf);
        printf("The error: %s", errbuf);
        return;
    }
      char *strp = BN_bn2dec(myDSA->p);          //将16进制转化为10进制
      char *strq = BN_bn2dec(myDSA->q);
      char *strg = BN_bn2dec(myDSA->g);

      ZZ m_q,m_g,m_p;
      m_p=to_ZZ(strp);
      m_q=to_ZZ(strq);
      m_g=to_ZZ(strg);

      cout<<endl;;
      cout<<"m_p="<<m_p<<"\n"<<endl;
      cout<<"m_q="<<m_q<<"\n"<<endl;  
      cout<<"m_g="<<m_g<<"\n"<<endl;   
      cout<<"按任意键继续\n"<<endl;  
      getch();

//……………………密钥计算部分…………………………
     
      ZZ xa,xb,ya,yb;
      xa=RandomBnd(m_q-1)+1;           //产生一个随机数,将其值赋给变量xa
      xb=RandomBnd(m_q-1)+1;
      ya=PowerMod(m_g,xa,m_p);          //计算对应公钥
      yb=PowerMod(m_g,xb,m_p);
      cout<<"Alice的私钥="<<xa<<endl;
      cout<<"按任意键计算Alice的公钥..."<<endl;
      getch();
      cout<<"Alice的公钥="<<ya<<"\n"<<endl;
      cout<<"Bob的私钥="<<xb<<endl;
      cout<<"按任意键计算Bob的公钥..."<<endl;
      getch();
      cout<<"Bob的公钥="<<yb<<"\n"<<endl;
      cout<<"…………密钥计算完毕…………\n"<<endl;
      getch();
这个怎么样
#9
ljh88882013-05-06 10:16
  。。
#10
azzbcc2013-05-06 11:11
#11
wp2319572013-05-06 11:12
没分  代码要全
#12
ljh88882013-05-06 12:49
回复 10楼 azzbcc
求分析啊
#13
ljh88882013-05-06 12:50
回复 11楼 wp231957
代码实在太多,300多行,贴不出来啊
#14
azzbcc2013-05-06 12:56
原来是太长,,我还以为是什么国家机密呢、、、

发附件啊
#15
辰星睿2013-05-06 15:13
PowerMod(c,1,m_p);这个函数参数传递的不对吧,你仔细核对下 这个函数参数的类型这些
#16
ljh88882013-05-06 16:42
回复 14楼 azzbcc
只有本站会员才能查看附件,请 登录
#17
ljh88882013-05-06 16:43
回复 15楼 辰星睿
就是没看懂啊,附件有全部代码。求分析
拙计啊。。
#18
azzbcc2013-05-06 17:15
NTL库没用过,查了一点资料
程序代码:
ZZ PowerMod(const ZZ& a, const ZZ& e, const ZZ& n)
{
   if (e == 0) return to_ZZ(1);

   long k = NumBits(e);

   ZZ res;
   res = 1;

   for (long i = k-1; i >= 0; i--) {
      res = (res*res) % n;
      if (bit(e, i) == 1) res = (res*a) % n;
   }

   if (e < 0)
      return InvMod(res, n);
   else
      return res;
}


把 4L倒数第 2行的 1改成 ZZ型试试,应该是要三个参数都是 ZZ型才可以
#19
ljh88882013-05-06 17:55
回复 18楼 azzbcc
咋有个错误说error C2601: 'PowerMod' : local function definitions are illegal
#20
邓士林2013-05-06 23:58
情歌对唱
#21
ljh88882013-05-07 08:13
回复 20楼 邓士林
...
#22
azzbcc2013-05-07 12:54


你怎么改的。。。

m_r = PowerMod(m_c, to_ZZ(1), m_p);
1