Beispiel #1
0
/**
 * \fn void dechiffrement(const char* nom_fichier, mpz_t d, mpz_t n, unsigned int blocs)
 * \brief déchiffrement d'un fichier binaire avec la clé privée
 * \param nom_fichier le nom du fichier à déchiffrer
 * \param d premier nombre de la clé
 * \param n second nombre de la clé
 * \param blocs taille des blocs
 * */
void dechiffrement(const char* nom_fichier, mpz_t d, mpz_t n, unsigned int blocs)
{
    FILE *fchiffre, *fclair;
    unsigned char *buffer, *buffer2;
    char nom_fichier_dechiffrer[100];
    mpz_t temp,temp2;
    int taille;
    clock_t s1,s2;

    mpz_init(temp);
    mpz_init(temp2);
	
    strcpy(nom_fichier_dechiffrer,nom_fichier);
    strcat(nom_fichier_dechiffrer,".decrypt");

    fchiffre = fopen(nom_fichier,"rb"); // ouverture fichier chiffré
	
    if (fchiffre != NULL)
    {
	s1 = clock();
	fclair = fopen(nom_fichier_dechiffrer,"wb+");
	
	buffer = (unsigned char*)calloc((blocs+1), sizeof(unsigned char));
	buffer2 = (unsigned char*)calloc((blocs), sizeof(unsigned char));
		
	fread(&taille,sizeof(int),1,fchiffre); //lecture de la taille du fichier 
		
	while(fread(buffer,sizeof(unsigned char), blocs+1, fchiffre) > 0)
	{	
	    conversion10(temp,buffer,blocs+1); // conversion base 10
	    mpz_powm_sec(temp2,temp,d,n); // déchiffrement
	    conversion256(buffer2,temp2,blocs); // convertion base 256
	    	    	
	    if (taille < blocs && taille > 0)	
		decalage(buffer2, &blocs); // suppression des caractères inutiles
			
	    fwrite(buffer2,sizeof(unsigned char),blocs,fclair); // écriture dans le fichier clair
	    taille-=blocs;
	    mpz_init(temp);
	}
	
	free(buffer);
	free(buffer2);
	fclose(fclair);
	fclose(fchiffre);
	s2 = clock();
	printf ("=> Déchiffrement effectué avec succés (%.2fs) dans %s\n", (float)(s2-s1)/CLOCKS_PER_SEC,nom_fichier_dechiffrer);
    }
	
    else
	printf("Fichier %s introuvable !\n", nom_fichier);
	
    mpz_clear(temp);
    mpz_clear(temp2);
}
Beispiel #2
0
// MAIN
int main()
{	
	int a,b;
	TABLEAU jean;
	/*printf("%lu \n", sizeof(TABLEAU));*/
	srand(time(NULL));
	jean= init_tab(jean);
	affiche_tab(jean);
	a = multi( jean);
	b = min(jean);
	printf("produit : %d, min : %d \n ", a,b);
	jean = decalage(jean);
	affiche_tab(jean);
	printf("\n");
	jean = trirapide(jean, 0, jean.taille);
	affiche_tab(jean);
	return 0;
}
Beispiel #3
0
int main(int argc, char **argv)
{
	srand((time)NULL);
	
	
	printf("Taille structure = %u\n", sizeof(Tableau)); // (taille du tableau * taille int) + (taille du champs 'taille') = 100*4 + 1 = 404
	

/*	int a = 0; // On initialise arbitrairement la variable a
	printf("%d\n", alea(a));	
*/
	
	Tableau T = initialise(T);
	
	affiche(T);
	printf("Elément minimum du tableau : %d\n", minimum(T));
	if (produit(T) < 0) printf("Produit trop grand"); // Evite d'afficher un produit négatif sur des entiers non signés
	else printf("Produit des éléments du tableau : %d\n", produit(T));
	
	
	// Décalage //
	T = decalage(T); 
	putchar('\n'); 
	printf("Tableau après décalage : \n"); 
	affiche(T);	
	printf("Taille du tableau après le décalage = %d\n\n", T.taille);
	
	
	// Trie //
	printf("Après trie du tableau : \n");
	T = trie(T);
	affiche(T);	
	
	
	return 0;
}
Beispiel #4
0
/*PRICING*/
static int putamer_carr(double S,NumFunc_1 *p,double T,double r,double divid,double sigma,double *put_price,double *put_delta)
	 
{
  double s1[1],s2[2],s3[3],s_1[2],s_2[3],s_3[4];
  double s1h[1],s2h[2],s3h[3],s_1h[2],s_2h[3],s_3h[4];
  double P1,P2,P3,P1_h,P2_h,P3_h;
  
  critical_stripped_prices(S,p->Par[0].Val.V_DOUBLE,T,r,divid,sigma,s1,s2,s3);
  decalage(s1,1,s_1,p->Par[0].Val.V_DOUBLE);  
  decalage(s2,2,s_2,p->Par[0].Val.V_DOUBLE);  
  decalage(s3,3,s_3,p->Par[0].Val.V_DOUBLE);  
 
  pricing1(S,p->Par[0].Val.V_DOUBLE,T,r,divid,sigma,&P1,s_1);  
  pricing2(S,p->Par[0].Val.V_DOUBLE,T,r,divid,sigma,&P2,s_2);  
  pricing3(S,p->Par[0].Val.V_DOUBLE,T,r,divid,sigma,&P3,s_3);
	
  critical_stripped_prices(S+AP_carr_h,p->Par[0].Val.V_DOUBLE,T,r,divid,sigma,s1h,s2h,s3h);
  
  decalage(s1h,1,s_1h,p->Par[0].Val.V_DOUBLE);
  decalage(s2h,2,s_2h,p->Par[0].Val.V_DOUBLE);
  decalage(s3h,3,s_3h,p->Par[0].Val.V_DOUBLE);     
	  
  pricing1(S+AP_carr_h,p->Par[0].Val.V_DOUBLE,T,r,divid,sigma,&P1_h,s_1h);       
  pricing2(S+AP_carr_h,p->Par[0].Val.V_DOUBLE,T,r,divid,sigma,&P2_h,s_2h);     
  pricing3(S+AP_carr_h,p->Par[0].Val.V_DOUBLE,T,r,divid,sigma,&P3_h,s_3h);
	  
  /*Price*/
  *put_price=2.*P2-P1;
  /**put_price=4.5*P3-4*P2+0.5*P1;*/

  /*Delta*/
  *put_delta=(2.*P2_h-P1_h-*put_price)/AP_carr_h;
  /**put_delta=((4.5*P3_h-4*P2_h+0.5*P1_h)-(*put_price))/AP_JU_h;*/

  return OK;
}