首页
社区
课程
招聘
未解决 [求助]关于C++大数运算的疑问
发表于: 2020-5-4 09:24 2537

未解决 [求助]关于C++大数运算的疑问

2020-5-4 09:24
2537

Big p( "D4B49D04A01EF209121C370DCF0D6292569EC65B8F147A8C62319B6B90DE"
"A2D1CD45199B93582732BFEE27F40BF62D7EB2559BCD08041E301E0D14037A25D989" );

 

上面的定义p的值应该是多少?


[注意]传递专业知识、拓宽行业人脉——看雪讲师团队等你加入!

收藏
免费 0
支持
分享
最新回复 (6)
雪    币: 11705
活跃值: (975)
能力值: ( LV12,RANK:779 )
在线值:
发帖
回帖
粉丝
2
这是一个512 bit的素数, 16进制字符串表示:
P .hex = D4B49D04A01EF209121C370DCF0D6292569EC65B8F147A8C62319B6B90DEA2D1CD45199B93582732BFEE27F40BF62D7EB2559BCD08041E301E0D14037A25D989

10进制打印是这个:
P.dec =
11140292070079840223478293553825852579756307272457526758455407348073991859638132039548754407195116517701496420375917235366272153337274234749677181046479241
2020-5-4 10:17
0
雪    币: 181
活跃值: (621)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
3
定义p的值应该是多少。。。。。
我觉得你应该想把P当数组。然后想问数组的大小。要求是C++不是C,所以Big应该是你封装接受数的类,至少是 
explicit Big::Big(const std::wstring & data) ; 这样一个模型
然后把数据往 vector<UCHAR>里面塞。
2020-5-4 10:19
0
雪    币: 220
活跃值: (243)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
4
我个人倾向于readyu的说法,因为p不是数组,是微软椭圆签字的公钥
2020-5-4 12:02
0
雪    币: 220
活跃值: (243)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
5
但是我认为p的十进制结尾不是1, 因该是7才对。
2020-5-4 12:06
0
雪    币: 220
活跃值: (243)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
6
已知osid为5080936, p为D4B49D04A01EF209121C370DCF0D6292569EC65B8F147A8C62319B6B90DEA2D1CD45199B93582732BFEE27F40BF62D7EB2559BCD08041E301E0D14037A25D989,a为1,b为0,gx为828A23E65A03F2CE12342DC2B3AA4089C1447DD5C4DC36C0470885A4662F10187037F72B2216C3F671B434267A329BD3363BB27055F0EBBA8A0ABEF451D3F6A3,gy为23B0823295C9CB669E1643B298624083F68C58F14FEEC55D0B247EF37B353A1066F502D7BC71050056C7D006156A26CC9222F5135FB8B255D7773AE0CDCA31E2,kx为25FEB90513F63C0833F1096369149E65C9359F4BCC8DE9A8F647030F96485BC71929594FF369DB967910B8F0A59BC7C30CF0D38311486293BA0B2952EE648E5F,ky为A186A2C2913E5584F05E97D3CD49E354E6C41BE329877D7FCC7B2BF877A0B00C9298901D305D7FF012FF7902B4202D4ED64D6A90C6AD05960253BAB8F69D68BF,q为41601E16BF4A1621,k为29AD943EA2EA15,却无法计算出正确的hash值5AA62EB和Sign值564E8259,能否帮忙看看下面的算法是否有问题?

char  szKey[30] = {0};

        Miracl precision( 0x64, 0 );
        miracl *mip = &precision;
        mip->IOBASE = 0x10;

        Big  p( "D4B49D04A01EF209121C370DCF0D6292569EC65B8F147A8C62319B6B90DE"
                "A2D1CD45199B93582732BFEE27F40BF62D7EB2559BCD08041E301E0D14037A25D989" );
        Big  a( "1" );
        Big  b( "0" );
        Big  gx( "828A23E65A03F2CE12342DC2B3AA4089C1447DD5C4DC36C0470885A4662F"
                "10187037F72B2216C3F671B434267A329BD3363BB27055F0EBBA8A0ABEF451D3F6A3" );
        Big  gy( "23B0823295C9CB669E1643B298624083F68C58F14FEEC55D0B247EF37B35"
                "3A1066F502D7BC71050056C7D006156A26CC9222F5135FB8B255D7773AE0CDCA31E2" );
        Big  kx( "25FEB90513F63C0833F1096369149E65C9359F4BCC8DE9A8F647030F9648"
                "5BC71929594FF369DB967910B8F0A59BC7C30CF0D38311486293BA0B2952EE648E5F" );
        Big  ky( "A186A2C2913E5584F05E97D3CD49E354E6C41BE329877D7FCC7B2BF877A0"
                "B00C9298901D305D7FF012FF7902B4202D4ED64D6A90C6AD05960253BAB8F69D68BF" );
        Big  q( "41601E16BF4A1621" );
        Big  k( "29AD943EA2EA15" );

        int  i, j;
        Big  sn, prefix, sign, hash, osid;
        if( bFirstRun )  srand( (unsigned int)time(NULL) );  // 只在第一次运行时初始化随机函数
        prefix = rand() % 0x400;
        osid = "0500";

        Big upperlimit = "4000000000000000";
        if( bFirstRun )  irand( (unsigned)time(NULL) );  // 只在第一次运行时初始化随机函数
    while( 1 )
        {
                sha sh;        
                unsigned char buf[128], s[11], m[131], sha_out[20];
                unsigned long dw;

                ecurve( a, b, p, MR_PROJECTIVE );
                ECn  G( gx, gy ), K( kx, ky ), R;
                Big  rx, ry;
                Big  r = rand( q );
                R = r*G;
                R.get( rx, ry );

                m[0] = 0x79;
                to_binary( osid, 2, (char*)buf, TRUE );
                m[1] = buf[1];
                m[2] = buf[0];
                to_binary( rx, 64, (char*)buf, FALSE );
                for ( i=63,j=3; i>=0; i--,j++ )  m[j] = buf;
                to_binary( ry, 64, (char*)buf, FALSE );
                for ( i=63,j=67; i>=0; i--,j++ ) m[j] = buf;
                
                shs_init( &sh );
                for( i=0; i<131; i++ )
                        shs_process( &sh, m );
                shs_hash( &sh, (char*)sha_out );

                memcpy( &dw, sha_out, 4 );
                dw = dw & 0x7FFFFFFF;
                hash = (long)dw;

                s[0] = 0x5D;
                to_binary( osid, 2, (char*)buf, TRUE );
                s[1] = buf[1];
                s[2] = buf[0];
                s[3] = dw & 0xff;
                s[4] = dw>>8 & 0xff;
                s[5] = dw>>16 & 0xff;
                s[6] = dw>>24 & 0xff;
                to_binary( prefix, 2, (char*)buf, TRUE );
                s[7] = buf[1];
                s[8] = buf[0];
                s[9] = 0x00;
                s[10] = 0x00;
                
                shs_init( &sh );
                for( i=0; i<11; i++ )
                        shs_process( &sh, s );
                shs_hash( &sh, (char*)sha_out );

                memcpy( &dw, sha_out+4, 4 );
                dw = dw>>2;
                Big  hout = (long)dw;
                memcpy( &dw, sha_out, 4 );
                hout = (hout<<32) + (long)dw;

                Big  kh = k*hout*(q+1)/2;
                Big  kr = ( pow( kh, 2 ) + r ) % q;
                Big  sr = sqrt( kr, q ); // 求平方根,失败的几率很大
                if( sr == 0 ) continue;  // 如果sqrt运行失败
                sign = ( sr - kh ) % q;
                while( sign < 0 )  sign += q;  // sign不会是负数  
                if( sign < upperlimit ) break;  // 如果sign在允许的范围内
        }

        sn = prefix;
        sn = (sn<<62) + sign;
        sn = (sn<<31) + hash;
        sn = (sn<<11) + osid;
2020-5-4 12:26
0
雪    币: 1540
活跃值: (2807)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
7
很想知道楼主是否解决问题了?
2020-5-4 15:05
0
游客
登录 | 注册 方可回帖
返回
//