Exemplo n.º 1
0
void
CCTPlate3d :: giveNodeCoordinates(double &x1, double &x2, double &x3,
                                  double &y1, double &y2, double &y3,
                                  double *z)
{
    FloatArray nc1(3), nc2(3), nc3(3);

    this->giveLocalCoordinates( nc1, * ( this->giveNode(1)->giveCoordinates() ) );
    this->giveLocalCoordinates( nc2, * ( this->giveNode(2)->giveCoordinates() ) );
    this->giveLocalCoordinates( nc3, * ( this->giveNode(3)->giveCoordinates() ) );

    x1 = nc1.at(1);
    x2 = nc2.at(1);
    x3 = nc3.at(1);

    y1 = nc1.at(2);
    y2 = nc2.at(2);
    y3 = nc3.at(2);

    if ( z ) {
        z [ 0 ] = nc1.at(3);
        z [ 1 ] = nc2.at(3);
        z [ 2 ] = nc3.at(3);
    }
}
Exemplo n.º 2
0
void
TrPlaneStrRot3d :: giveNodeCoordinates(FloatArray &x, FloatArray &y)
{
    FloatArray nc1(3), nc2(3), nc3(3);

    this->giveLocalCoordinates( nc1, * ( this->giveNode(1)->giveCoordinates() ) );
    this->giveLocalCoordinates( nc2, * ( this->giveNode(2)->giveCoordinates() ) );
    this->giveLocalCoordinates( nc3, * ( this->giveNode(3)->giveCoordinates() ) );

    x.at(1) = nc1.at(1);
    x.at(2) = nc2.at(1);
    x.at(3) = nc3.at(1);

    y.at(1) = nc1.at(2);
    y.at(2) = nc2.at(2);
    y.at(3) = nc3.at(2);

    //if (z) {
    //  z[0] = nc1->at(3);
    //  z[1] = nc2->at(3);
    //  z[2] = nc3->at(3);
    //}
}
Exemplo n.º 3
0
void main()
{
    FILE* fp;
    fp=fopen("ls_mb.txt","a");
    fprintf(fp,"-----------------------------------------------\n");
    fprintf(fp,"             start of program                  \n");
    fprintf(fp,"-------------------------------------------------");
    printf("Enter no of nodes:");
    scanf("%d",&no_of_node);
    printf("\nTotal nodes in the network: %d",no_of_node);
    fprintf(fp,"\nTotal nodes in the network: %d",no_of_node);
    for(a=2; a<200; a++)
    {
        count=0;
        for(a1=1; a1<=(a/2); a1++)
        {
            if(a1!=1)
            {
                if((a%a1)==0)
                    count+=1;
            }
        }
        if(count==0)
        {
            prime[zp]=a;
            prime[++zp]=a*a;
            zp++;
        }
    }
    temp=0;
    for (i=0; i<zp-1; i++)
    {
        for (j=0; j<zp-1-i; j++)
        {
            if (prime[j]>prime[j+1])
            {
                temp=prime[j];
                prime[j]=prime[j+1];
                prime[j+1]=temp;
            }
        }
    }
    temp=0;

//finding q for given n where k=(q*q)
    for(z1=0; z1<zp; z1++)
    {
        z2=prime[z1];
        temp=z2*z2;
        if(no_of_node<=temp)
        {
            p=prime[z1];
            break;
        }
    }
    for(z1=0; z1<zp; z1++)
    {
        z2=prime[z1];
        temp=z2*z2;
        if(no_of_node<=temp)
        {
            r=prime[z1];
            break;
        }
    }
    int pt;
    if(isprime(p)==1)
        pt=p;
    if(isprime(p)==0)
        pt=sqrt(p);
    int r1=r*r;
    float r1c2=r1*(r1-1)*0.5;
   // fprintf(fp,"\nqt : %d\n",pt);
    printf("\n p=%d",p);
    printf("\n r=%d",r);
    printf("\nenter value of k(2-%d) (keys per node)",p);
    scanf("%d",&k);
    fprintf(fp,"\nkeys per node : %d",k);
    fprintf(fp,"\nr : %d",r);
    int x=r+1;
    float px=(float) k/x;
    //printf("\npx: %f",px);
    //fprintf(fp,"\npx: %f",px);
    //printf("\nnodes: \n");
    //fprintf(fp,"\n p=%d",p);
    //fprintf(fp,"\nnodes: \n");

    for(i=0; i<p; i++)
    {
        for(j=0; j<p; j++)
        {
            node[count1][0]=i;
            node[count1][1]=j;
            count1++;
            //printf("N(%d,%d) ",i,j);
 //           fprintf(fp,"N(%d,%d) ",i,j);
        }
       // printf(";;\n");
   //     fprintf(fp,"\n");
    }
//printf("%d",count1);
//set of keys
    //fprintf(fp,"\n keys : \n");
  /*  for(a1=0; a1<k; a1++)
    {
        for(a2=0; a2<p; a2++)
        {
            fprintf(fp,"(%d,%d)",a1,a2);
        }
        fprintf(fp,"\n");
    }*/
    a1=0;
    a2=0;
    a3=0;
// calculating keys
    int l_t;
    if(isprime(p)==1)
    {
        for(a1=0; a1<p; a1++)  //a:a1 b:a2 x:a3 key(x,ax+b mod p)
        {
            for(a2=0; a2<p; a2++)
            {
                for(a3=0; a3<k; a3++)
                {
                    key_set[a1*p+a2][a3][0]=a3;
                    key_set[a1*p+a2][a3][1]=((a1*a3)+a2)%p;
                }
            }
        }
    }

    else
    {
        vectorize(p);
        printf("\nEnter the irreducable polynomial in z(%d)(From higher to lower degree)",pt);
        for(l_t=2;l_t>=0;l_t--)
        {
            printf("\nX^%d:",l_t);
            scanf("%d",&irr_poly[l_t]);
        }
        for(a1=0; a1<p; a1++)  //a:a1 b:a2 x:a3 key(x,ax+b mod p)
        {
            for(a2=0; a2<p; a2++)
            {
                for(a3=0; a3<k; a3++)
                {
                    key_set[a1*p+a2][a3][0]=a3;

                    poly_a[0]=vector[a1][0];
                    poly_a[1]=vector[a1][1];

                    poly_b[0]=vector[a2][0];
                    poly_b[1]=vector[a2][1];

                    poly_x[0]=vector[a3][0];
                    poly_x[1]=vector[a3][1];

                    mulpoly(poly_a,poly_x);
                    addpoly(mul_poly,poly_b);
                    //printf("\n %dX^2+%dX+%d + %dX+%d=%dX^2+%dX+%d",mul_poly[2],mul_poly[1],mul_poly[0],poly_b[1],poly_b[0],add_poly[2],add_poly[1],add_poly[0]);

                    add_poly[0]=add_poly[0]%pt;
                    add_poly[1]=add_poly[1]%pt;
                    add_poly[2]=add_poly[2]%pt;

                    //printf("\n %dX^2+%dX+%d",add_poly[2],add_poly[1],add_poly[0]);

                    while(1)
                    {
                        if((add_poly[2]-irr_poly[2]<0)||(add_poly[1]-irr_poly[1]<0)||(add_poly[0]-irr_poly[0]<0))
                            break;
                        else
                            add_poly[2]=add_poly[2]-irr_poly[2];
                            add_poly[1]=add_poly[1]-irr_poly[1];
                            add_poly[0]=add_poly[0]-irr_poly[0];
                    }

                    //printf("\n %dX^2+%dX+%d",add_poly[2],add_poly[1],add_poly[0]);

                    if((add_poly[2]!=0)&&(add_poly[1]!=0)&&(add_poly[0]==0))   //const 0
                    {
                        add_poly[1]=add_poly[1]+add_poly[2]*irr_poly[1];
                        add_poly[0]=add_poly[2]*get_x_bar(irr_poly[0],pt);
                        add_poly[2]=0;
                    }

                    if((add_poly[2]!=0)&&(add_poly[1]==0)&&(add_poly[0]!=0))     //X 0
                    {
                        add_poly[1]=add_poly[2]*irr_poly[1];
                        add_poly[0]=add_poly[0]+add_poly[2]*get_x_bar(irr_poly[0],pt);
                        add_poly[2]=0;
                    }

                    if((add_poly[2]!=0)&&(add_poly[1]==0)&&(add_poly[0]==0))        //const,X 0
                    {
                        add_poly[1]=add_poly[2]*irr_poly[1];
                        add_poly[0]=add_poly[2]*get_x_bar(irr_poly[0],pt);
                        add_poly[2]=0;
                    }

                    add_poly[0]=add_poly[0]%pt;
                    add_poly[1]=add_poly[1]%pt;
                    add_poly[2]=add_poly[2]%pt;

                    //printf("\n %dX^2+%dX+%d",add_poly[2],add_poly[1],add_poly[0]);

                    if((add_poly[2]==0)&&(add_poly[1]==0)&&(add_poly[0]==0))          //all 0
                    {
                        key_set[a1*p+a2][a3][1]=0;
                    }


                    if((add_poly[2]==0)&&(add_poly[1]!=0)&&(add_poly[0]!=0))       //X^2 0
                    {
                        key_set[a1*p+a2][a3][1]=add_poly[1]*pt+add_poly[0];
                    }

                    if((add_poly[2]==0)&&(add_poly[1]!=0)&&(add_poly[0]==0))        //X^2, const 0
                    {
                        key_set[a1*p+a2][a3][1]=add_poly[1]*pt;
                    }

                    if((add_poly[2]==0)&&(add_poly[1]==0)&&(add_poly[0]!=0))         //X^2,X 0
                    {
                        key_set[a1*p+a2][a3][1]=add_poly[0];
                    }



                    for(l_t=2;l_t>=0;l_t--)
                    {
                        add_poly[l_t]=0;
                        mul_poly[l_t]=0;
                    }
                }
            }
        }
    }
//print keys
    //fprintf(fp,"\n");
    printf("\n");
    //convert keys to single number
    for(a1=0; a1<p; a1++)
    {
        for(a2=0; a2<p; a2++)
        {
            for(a3=0; a3<k; a3++)
            {
                key_set_stat[a1*p+a2][a3]=key_set[a1*p+a2][a3][0]+key_set[a1*p+a2][a3][1]*p;
            }
        }
    }

    /*for(a1=0; a1<p; a1++)
    {
        for(a2=0; a2<p; a2++)
        {
            for(a3=0; a3<k; a3++)
            {
                printf("%d, ",key_set_stat[a1*p+a2][a3]);
            }
            printf("\n");
        }
    }*/

    // calculate E(s) and V(s)
    int compromised_node,a4,compromised[500];
    printf("Enter number of compromised nodes");
    scanf("%d",&compromised_node);
    for(a4=0; a4<compromised_node; a4++)
    {
        compromised[a4]=rand()%no_of_node;
    }
    //printf("\n compromised node ids : ");
    /*for(a4=0; a4<compromised_node; a4++)
    {
        printf("\n%d",compromised[a4]);
    }*/
    //printf("\ncompromised keys::");
    int compromised_keys[10000];
    count1=0;
    for(a1=0; a1<compromised_node; a1++)
    {
        //printf("C%d",compromised[a1]);
        for(a2=0; a2<k; a2++)
        {
            compromised_keys[count1]=key_set_stat[compromised[a1]][a2];
            //printf("%d,",compromised_keys[count1]);
            count1+=1;
        }
        //printf("\n");
    }
    //printf("\ncount1=%d",count1);
    //E(s) calculation
    int unique_key=0;
   for(a1=0;a1<15000;a1++)
    {
        key_ES[a1]=0;
    }
    for(a1=0;a1<count1;a1++)
    {
        key_ES[compromised_keys[a1]]++;
    }
    for(a1=0;a1<15000;a1++)
    {
        if(key_ES[a1]!=0)
        unique_key++;
    }
    printf("\n U:%d",unique_key);

    float broken_links,total_links,es;
    broken_links=(float)unique_key*nc2(p);
    total_links=(float)p*k*nc2(p);
    es=broken_links/total_links;
    printf("\nes::%f",es);

    fprintf(fp,"-----------------------------------------------\n");
    fprintf(fp,"             end of program                  \n");
    fprintf(fp,"-------------------------------------------------");
}