1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
void crypter(void)
{
FILE *source_crypt;
FILE *res_crypt;
unsigned char c;
unsigned long int i=0;
unsigned long int k,n,e;
char nom_fichier[20];
printf("\n\n\t\t\t *********\n");
printf("\t\t\t *CRYPTER*\n");
printf("\t\t\t *********\n\n\n\n");
fflush(stdin);
printf("Donner le nom du fichier source avec son extension : ");
gets(nom_fichier);
printf("\n\n\n\tdonner votre cle publique n : ");
scanf("%d",&n);
printf("\n\n\n\tdonner votre cle publique e : ");
scanf("%d",&e);
source_crypt=fopen(nom_fichier,"rb");
if(source_crypt==NULL)
{
printf("Impossible d'ouvrir le fichier source.\n");
}
res_crypt=fopen("result.cry" , "wb");
if(res_crypt==NULL)
{
printf("Impossible d'ouvrir le fichier resultat.\n");
}
clrscr();
printf("\n\n\t\tATTENDEZ SVP PENDANT LE CRYPTAGE.");
while((feof(source_crypt)==0) && (fread(&c,sizeof(unsigned char),1,source_crypt)!=0))
{
fseek(source_crypt,sizeof(unsigned char)*i,SEEK_SET);
fread(&c,sizeof(unsigned char),1,source_crypt);
k=crypt(c,n,e);
fwrite(&k,sizeof(unsigned long int),1,res_crypt);
i=i+1;
}
fclose(source_crypt);
fclose(res_crypt);
printf("\n\n\n\n\n\n\n\n\n\nLe cryptage de votre fichier est termine.");
printf("\n\nvotre fichier crypter se nomme result.cry");
getch();
}
/******************************FONCTION CRYPTAGE*******************************/
unsigned long int crypt(unsigned char k,unsigned long int n,unsigned long int e)// k:c'est le message qu'on va l'inserer
{
unsigned long int i,res=1,nbre;
nbre=((unsigned long int)k);
for(i=0;i<e;i++)
{
res = res * nbre;
res=fmod(res,n);
}
return res;
} |
Partager