bonjour
est ce que je peux écrire la méthode dans une classe qui est déclarée dans un fichier .h au lieu d'écrire seulement les prototypes des méthodes. Puis, je compile le méthodes dans un autre fichier .c se differer au 1ère classe c'est-à-dire par exemple
au lieu d'écrire ce code dans RSA.h
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
class Rsa
{
    public:
        Rsa();
        ~Rsa();
     unsigned long int crypt(unsigned char k,unsigned long int n,unsigned long int e);
    unsigned char decrypt( unsigned long int k,unsigned long int d,unsigned long int n);
    void crypter(void);
    void decrypter(void);
    void inscri(void);
    int p_e_e2(int x);
 
#endif // RSA_H_INCLUDED
on va écrire dans RSA.h ce code qui contient les corps de méthode et non pas seulement les prototypes comme ça
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
#ifndef RSA_H_INCLUDED
#define RSA_H_INCLUDED
 
#include <string>
 
class Rsa
{
    public:
        Rsa();
        ~Rsa();
void crypter(void)
    {
    FILE *source_crypt;
    FILE *res_crypt;
    Ptr<Vehicle> veh;
    unsigned char c= veh->Getwrg();//Getwrg c'est une focntion qui va get le message warning qui est enregistre dans Setwrg
    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;
    }
    /*******************************DECRYPTER**************************************/
    void decrypter(void)
    {
    FILE *source;
    FILE *res_decrypt;
    char l;
    unsigned long int h=0;
    unsigned long int d,n;
    unsigned long int lect_int;
    char nom_fichier[20],nom_fin[20];
    printf("\n\n\t\t\t ***********\n");
    printf("\t\t\t *DECRYPTER*\n");
    printf("\t\t\t ***********\n\n\n\n");
    fflush(stdin);
    printf("Donner le nom du fichier avec son extension : ");
    gets(nom_fichier);
    printf("Donner le nom du fichier de destination avec son extension : ");
    gets(nom_fin);
    printf("\n\n\n\tdonner votre cle prive n : ");
    scanf("%d",&n);
    printf("\n\n\n\tdonner votre cle prive d : ");
    scanf("%d",&d);
    source=fopen(nom_fichier , "rb");
    if(source==NULL)
    {
    printf("Impossible d'ouvrir le fichier a decrypter.\n");
    erreur();
    }
    res_decrypt=fopen(nom_fin , "wb");
    if(res_decrypt==NULL)
    {
    printf("Impossible d'ouvrir le fichier resultat.\n");
    erreur();
    }
    clrscr();
    printf("\n\n\t\tATTENDEZ SVP PENDANT LE DECRYPTAGE.");
    while((feof(source)==0) && (fread(&lect_int,sizeof(unsigned long int),1,source)!=0))
    {
    fseek(source,sizeof(unsigned long int)*h,SEEK_SET);
    fread(&lect_int,sizeof(unsigned long int),1,source);
    l=decrypt(lect_int,d,n);
    fwrite(&l,sizeof(unsigned char),1,res_decrypt);
    h=h+1;
    }
    fclose(source);
    fclose(res_decrypt);
    printf("\n\n\n\n\n\n\n\n\n\nLe decryptage de votre fichier est termine.");
    getch();
    }
    /****************************FONCTION DECRYPTAGE*******************************/
    unsigned char decrypt(unsigned long int k,unsigned long int d,unsigned long int n)// k message crypté on va le decrypter
    {
    unsigned long int i,res=1;
    unsigned char x;
    for(i=0;i<d;i++)
    {
    res=res*k;
    res=fmod(res,n);
    }
    x=((unsigned char)res);
    return x;
    }
    /********************************LECTURE***************************************/
    void lecture(void)
    {
    int compteur_car;
    int compteur_ligne;
    int car_lect;
    FILE *fichier;
    char nom_fichier[20];
    printf("\n\n\t\t\t**********************\n");
    printf("\t\t\t*LECTURE D'UN FICHIER*\n");
    printf("\t\t\t**********************\n\n\n");
    fflush(stdin);
    printf("Donner le nom du fichier a lire (avec son extension) : ");
    gets(nom_fichier);
    fichier=fopen(nom_fichier,"r");
    if(fichier==NULL)
    {
    printf("\n\nImpossible d'ouvrir le fichier a lire.\n");
    }
    compteur_ligne=0;
    compteur_car=0;
    if(fichier!=NULL){
    printf("\n\nLecture du fichier en cours.\n\n");
    while((car_lect = fgetc(fichier))!=EOF)
    {
    compteur_car = compteur_car + 1;
    printf("%c",car_lect);
    if(compteur_car == 40)
    {
    compteur_car = 0;
    compteur_ligne = compteur_ligne + 1;
    }
    if(compteur_ligne>=17)
    {
    compteur_car = 0;
    compteur_ligne = 0;
    getch();
    clrscr();
    }
    }
    printf("\n\n\nLa lecture du fichier est terminee.");
    }
    fclose(fichier);
    getch();
    }
void inscri(void)
    {
    int p,q,e,z,d,n;
    clrscr();
    printf("\n\n\t\t\t\t*************\n");
    printf("\t\t\t\t*INSCRIPTION*\n");
    printf("\t\t\t\t*************\n\n\n");
    pq(&p,&q);
    n=p*q;
    z=(p-1)*(q-1);
    e=p_e_e2(z);
    printf("\n\n\n\n\n\n\n\n\t( n : %d ; e : %d ) est votre cle publique.",n,e);
    Vehicle::cople C;
           C.nb1 = n;
           C.nb2 = e;
           veh->insertKeyCP(C);
 
    d=cle_priv(e,z);
    printf("\n\n\n\n\t( n : %d ; d : %d ) est votre cle privee.",n,d);
    Vehicle::copple Cp;
           Cp.ent1 = n;
           Cp.ent2= d;
           veh->insertKeybDcP(Cp);
 
    getch();
    getch();
    getch();
    clrscr();
    choix_crypto();
    }
    /******************************************************************************/
    int p_e_e2(int x)
    {
    int y,*tab[100000],*taille,rep,i;
    taille=(int*)malloc(sizeof(int));
    *taille=0;
    for(i=0;i<100000;i++)
    {
    tab[i]=(int*)malloc(sizeof(int));
    }
    for(y=1;y<x;y++)
    {
    pgcd2(x,y,taille,tab);
    }
    randomize();
    rep=*tab[rand()%*taille];
    return rep;
    }
    /******************************************************************************/
    void pgcd2(int a,int b,int* taille,int* tab[])
    {
    int *reste,*k,*s,*q;
    reste=(int*)malloc(sizeof(int));
    k=(int*)malloc(sizeof(int));
    s=(int*)malloc(sizeof(int));
    q=(int*)malloc(sizeof(int));
    *s=a;
    *q=b;
    *reste=1;
    decomp(s,q,reste,k);
    while(*reste!=0&&*reste>0)
    {
    *s=*q;
    *q=*reste;
    decomp(s,q,reste,k);
    }
    if(*q==1)
    {
    *tab[*taille]=b;
    *taille=*taille+1;
    }
    }
};
 
#endif // RSA_H_INCLUDED