| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 671 人关注过本帖
标题:没有对值进行改动就自动变为0了,为什么
只看楼主 加入收藏
lyl930130
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:323
专家分:111
注 册:2013-5-13
结帖率:91.43%
收藏
已结贴  问题点数:20 回复次数:8 
没有对值进行改动就自动变为0了,为什么
int main()
{
    double p=0.75,Er,D,Tr;
    int x1[N]={0},x2[N]={0},x3[N]={0},x4[N]={0},z[N]={1,0,0,0,0,1,1,0,1,0,1,0,1,1,1,0,0,1,0,1,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,0,1,0,1,0,1,1,1,1,0,1,0,1,1,1,1,1,1,1,0,1,0,0,0,0,1,1,1,1,1,0,1,1,1,1,1,1,1,0,1,0,0,1,0,1,0,1,0,1,1,0,0,1,1,0,0,1,1,0,0,0,1,0,0,0,0,1,1,0,1,0,0,1,1,1,1,0,0,0,0,1,1,1,1,0,1,0,1,1,0,1,0,1,1,0,0,1,0,0,0,1,1,1,0,1,1,0,0,1,1,1,1,1,1,1,0,0,1,0,0,0,0,1,0,0,0,1,1,1,0,0,0,1,0,1,1,0,1,0,0,1,1,0,1,0,0,1,0,0,1,1,1,1,1,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,1,1,0,0,1,1,1,0,0,0,1,1,1,1,0,1,0,0,1,1,1,0,0,0,0,0,0,0,1,0,0,0,1,0,1,0,0,0};
    int i,ca;
    Er=N*(2*p-1);
    D=4*N*p*(1-p);
    Tr=Er-3.09*sqrt(D);
    for (i=0;i<32768;i++)//31977
    {
        ca=abs(acc_Ca(i,z));
        if((double)ca>=Tr)        //只有当i=31977时才满足条件
        {
            printf("%d    ",ca);
            printf("\n accept  %d     \n ",i);
            check(x1,x2,i);
            acc_x3x4(x1,x2,x3,x4,z);//当i=31977调试完这一步时,p,Er,D,Tr,的值全部变成了0
        }
    }
   
}

和注释中的一样,但是如果不调试acc_x3x4(x1,x2,x3,x4,z)这一步,p,Er,D,Tr,的值还是原来的状态
搜索更多相关主题的帖子: double 
2013-05-31 08:05
我叫沃恩
Rank: 12Rank: 12Rank: 12
来 自:Asia
等 级:贵宾
威 望:10
帖 子:1234
专家分:3865
注 册:2013-3-29
收藏
得分:0 
acc_x3x4(x1,x2,x3,x4,z);是什么意思?自定义函数??发一下代码吧!

因为我是菜鸟,所以应该被骂! 细节+坚持=成功!
2013-05-31 08:46
lyl930130
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:323
专家分:111
注 册:2013-5-13
收藏
得分:0 
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "related_attack.h"
#define N 250
void acc(int x,int p,int n,int x1[],int x2[],int x3[],int x4[],int z[],int y[]);
void acc_x1(int x[]);
void acc_x2(int x[]);
void acc_x3(int x[]);
void acc_x4(int x1[],int x2[],int x3[],int x4[],int z[]);
int g(int x,int y,int z,int w);
int ensure(int x1[],int x2[],int x3[],int x4[],int z[]);

void acc_x3x4(int x1[],int x2[],int x3[],int x4[],int x[])//x是z
{
    int b[14],k[14]={0};
    int i,j,n,p=0;
    acc_x1(x1);
    acc_x2(x2);
    for(i=0,j=0;i<14;i++)    //找可以由x1x2直接确定的x3x4
    {
        if(x1[i]==0&&x2[i]==0&&x[i]==1)
        {
            x3[i]=1;
            x4[i]=1;
            k[j]=i;
            j++;
        }
        else if(x1[i]==0&&x2[i]==1&&x[i]==0)
        {
            x3[i]=0;
            x4[i]=1;
            k[j]=i;
            j++;
        }
        else if(x1[i]==1&&x2[i]==0&&x[i]==0)
        {
            x3[i]=1;
            x4[i]=0;
            k[j]=i;
            j++;
        }
        else if(x1[i]==1&&x2[i]==1&&x[i]==1)
        {
            x3[i]=1;
            x4[i]=1;
            k[j]=i;
            j++;
        }
        
    }
    n=(int)pow(2.0,(double)(14-j));
    for(i=0;i<n;i++)
    {
        acc(i,p,n,x1,x2,x3,x4,x,k);    //p用作计数来判断x3x4是否合适
        if(p==250)
        {
            for(i=0;i<N;i++)
                if(i==0)
                    printf("x1序列:%d",x1[i]);
                else
                    printf("%d",x1[i]);
            printf("\n");
            for(i=0;i<N;i++)
                if(i==0)
                    printf("x2序列:%d",x2[i]);
                else
                    printf("%d",x2[i]);
            printf("\n");
            for(i=0;i<N;i++)
                if(i==0)
                    printf("x3序列:%d",x3[i]);
                else
                    printf("%d",x3[i]);
            printf("\n");
            for(i=0;i<N;i++)
                if(i==0)
                    printf("x4序列:%d",x4[i]);
                else
                    printf("%d",x4[i]);
            printf("\n");
        }
    }
}


    void acc (int x,int p,int n,int x1[],int x2[],int x3[],int x4[],int z[],int y[])
    {
        
        int i,j,k,m=0;
        for(i=0,j=0;i<14;i++)
        {
            if(i==y[j])
                j++;
            else
            {
                x3[i]=x%2;
                x=x/2;
            }
        }
        
        for(k=0;k<n;k++,m=k)
        {
            for(i=0,j=0;i<n;i++)
            {
                if(i==y[j])
                    j++;
                else
                {
                    x4[i]=m%2;
                    m=m/2;
                }
            }
            acc_x3(x3);
            acc_x4(x1,x2,x3,x4,z);
            p=ensure(x1,x2,x3,x4,z);
            //printf("%4d",p);
            if(p==250)
                break;
        }
    }

    void acc_x1(int x[])
    {
        int i;
        for(i=7;i<N;i++)
        {   
            x[i]=(x[i-7]+x[i-6]+x[i-4]+x[i-2])%2;
        }
    }// x7  x5  x3  x  1

    void acc_x2(int x[])
    {
        int i;
        for(i=8;i<N;i++)
            x[i]=(x[i-8]+x[i-7]+x[i-6]+x[i-1])%2;
    }// x8  x7  x2  x  1

    void acc_x3(int x[])
    {
        int i;
        for(i=14;i<N;i++)
            x[i]=(x[i-2]+x[i-12]+x[i-13]+x[i-14])%2;

    } //x14  x12  x2  x  1
    void acc_x4(int x1[],int x2[],int x3[],int x4[],int z[])
    {
        int i,j;
        for(i=14;i<20;i++)
            if(z[i]==g(x1[i],x2[i],x3[i],0))
                    x4[i]=0;
                else
                    x4[i]=1;
        for(i=20;i<N;i++)
            x4[i]=(x4[i-17])%2;
    }// x20  x3

    int g(int x,int y,int z,int w)
    {
        int i;
        i=(x+y+x*z+y*w+z*w+x*y*z+x*y*w)%2;
        return i;
    }//x1x2x1x3 x2x4x3x4x1x2x3x1x2x4

    int ensure(int x1[],int x2[],int x3[],int x4[],int z[])
    {
        int i;
        for(i=0;i<N;i++)
            if(z[i]!=g(x1[i],x2[i],x3[i],x4[i]))
                break;
        return i;
    }
2013-05-31 12:12
lyl930130
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:323
专家分:111
注 册:2013-5-13
收藏
得分:0 
回复 2楼 我叫沃恩
acc_x3x4程序有点小问题我还没找出来,但是就算是这样和p,Er,D,Tr这些值也没有关系啊,不明白为什么会变
2013-05-31 12:13
我叫沃恩
Rank: 12Rank: 12Rank: 12
来 自:Asia
等 级:贵宾
威 望:10
帖 子:1234
专家分:3865
注 册:2013-3-29
收藏
得分:7 
我看了你发的代码!不过确实没看懂!!不好意思帮不了你了!

因为我是菜鸟,所以应该被骂! 细节+坚持=成功!
2013-05-31 13:19
hsjjgm
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:106
专家分:189
注 册:2013-4-27
收藏
得分:7 
看着头晕
2013-05-31 13:26
lyl930130
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:323
专家分:111
注 册:2013-5-13
收藏
得分:0 
回复 5楼 我叫沃恩
木有关系,谢谢。不过,能不能叫几个过来帮忙一起看一下
2013-05-31 15:05
lyl930130
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:323
专家分:111
注 册:2013-5-13
收藏
得分:0 
回复 6楼 hsjjgm
只单纯看代码的确很头晕。。。
2013-05-31 15:06
lyl930130
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:323
专家分:111
注 册:2013-5-13
收藏
得分:0 
答题思路是这样,acc_x3x4之前都没问题,acc_x3x4求的是根据x1和x2两个250比特的数列求出x3和x4两个250比特的数列,acc_x1/2/3/4分别是根据前x比特生产后面的数据。acc主要功能是先根据x1x2确定前14比特中x3和x4中能够确定的数据,然后在非确定的地方开始穷举。但是就是这里好像有点问题
2013-05-31 15:14
快速回复:没有对值进行改动就自动变为0了,为什么
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018735 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved