コード例 #1
0
ファイル: rsa.c プロジェクト: woprandi/RSA
void calcul_cles(mpz_t p, mpz_t q, mpz_t phi, mpz_t n, mpz_t e, mpz_t d, unsigned int taille, gmp_randstate_t state)
{
    gpa(p,taille,state);
    premier(p);
    gpa(q,taille,state);
    premier(q);
    
    mpz_mul(n,p,q); // n = pq
    phi_n(phi,p,q); // phi = (p-1)*(q-1)
    
    mpz_set_ui(e,65537);
    calcul_d(d,e,phi); // calcul de d tel que e*d mod phi = 1
}
コード例 #2
0
ファイル: FnMap.cpp プロジェクト: clay-matt/Fn
FnMap FnMap::iterate(int n) const
{

    //returns the nth power of the automorphism
    //uses repeated squaring

    int i;
    FnMap phi_pow2(*this);
    FnMap phi_n(image_rank);

    // special cases
    if (n == 1) {
        return FnMap(*this);
    }
    if (phi_pow2.imageRank() != phi_pow2.domainRank()) {
      phi_n.fail();
      return phi_n;
    }
    if (n < 0)  { // eventually want this to take you to the inverse if possible...
      phi_n.fail();
      return phi_n;
    }

    QString n_base2 = QString::number(n,2); // convert n to base 2

    for (i = n_base2.length() - 1; i > 0; i--) {
         // if the ith digit in the base 2 representation of n is 1,
         // multiply phi_n by this power
         if(n_base2.at(i).digitValue() == 1) phi_n *= phi_pow2;
         // now square
         phi_pow2 *= phi_pow2;
    }

    // the first digit is always nonzero
    phi_n *= phi_pow2;

    return phi_n;

}
void mexFunction(
	int nlhs,              // Number of left hand side (output) arguments
	mxArray *plhs[],       // Array of left hand side arguments
	int nrhs,              // Number of right hand side (input) arguments
	const mxArray *prhs[]  // Array of right hand side arguments
)
{    
    // Note this function should be called in the outside m-function, supposely, 
    // ac_div_AOS_3D.m, legal tests of the inputs should be carried out there.
    const int *dims = mxGetDimensions(prhs[0]);   // dimensions of input
    C3DImage<double> phi(mxGetPr(prhs[0]), dims); // initial levelset
    double delta_t = mxGetScalar(prhs[2]); 
    
    // Generate output.
    plhs[0] = mxCreateNumericArray(3, dims, mxDOUBLE_CLASS, mxREAL);
    C3DImage<double> phi_n(mxGetPr(plhs[0]), dims);
    
    // feature map type 
    mxClassID g_type = mxGetClassID(prhs[1]);
    switch(g_type)
    {
        case mxINT8_CLASS:
        {
    		C3DImage<char> g((char*)mxGetPr(prhs[1]), dims);
            div_AOS_3D(phi, g, delta_t, phi_n);
            break;
        }
        case mxUINT8_CLASS:
        {
    		C3DImage<unsigned char> g((unsigned char*)mxGetPr(prhs[1]), dims);
            div_AOS_3D(phi, g, delta_t, phi_n);
            break;
        }
        case mxINT16_CLASS:
        {
    		C3DImage<short> g((short*)mxGetPr(prhs[1]), dims);
            div_AOS_3D(phi, g, delta_t, phi_n);
            break;
        }
        case mxUINT16_CLASS:
        {
    		C3DImage<unsigned short> g((unsigned short*)mxGetPr(prhs[1]), dims);
            div_AOS_3D(phi, g, delta_t, phi_n);
            break;
        }
        case mxINT32_CLASS:
        {
    		C3DImage<int> g((int*)mxGetPr(prhs[1]), dims);
            div_AOS_3D(phi, g, delta_t, phi_n);
            break;
        }
        case mxUINT32_CLASS:
        {
    		C3DImage<unsigned int> g((unsigned int*)mxGetPr(prhs[1]), dims);
            div_AOS_3D(phi, g, delta_t, phi_n);
            break;
        }
        case mxSINGLE_CLASS:
        {
    		C3DImage<float> g((float*)mxGetPr(prhs[1]), dims);
            div_AOS_3D(phi, g, delta_t, phi_n);
            break;
        }
        case mxDOUBLE_CLASS:       
        {
    		C3DImage<double> g((double*)mxGetPr(prhs[1]), dims);
            div_AOS_3D(phi, g, delta_t, phi_n);
            break;
        }
    }
}