Bonjour à tous,


j'ai créé la fonction de cryptage suivante:
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
 
char* crypter(char* chaine)
    {
        char* alphabet_normal = new char[30];
        alphabet_normal = "abcdefghijklmnopqrstuvwxyz ,;.";
        char* alphabet_secret = new char[30];
        alphabet_secret = ",;. abcdefghijklmnopqrstuvwxyz";
        //
        char* secret = new char[strlen(chaine)];
        char tmp;
        int tmp2 = 0;
        int unsigned i,j;
 
        for(i=0; i<strlen(chaine); i++)
        {
            tmp2 = -1;
            tmp = chaine[i];
            for(j=0; j<strlen(alphabet_normal); j++)
               if(alphabet_normal[j] == tmp)
                  tmp2 = j;
            if(tmp2 >=0)
               secret[i] =  alphabet_secret[tmp2];
            else
               secret[i] = chaine[i];
        }
        return secret;
    };
le problème que je rencontre se situe au niveau des fins de chaines, il m'ajoute des caractères bizares, par exemple si je veut crypter la chaine "test", je devrait avoir "paop", mais j'obtiens "paop¸"