Cryptage

skysee Messages postés 29 Date d'inscription mercredi 30 janvier 2002 Statut Membre Dernière intervention 28 septembre 2007 - 28 mars 2002 à 11:56
cs_Kaid Messages postés 949 Date d'inscription mardi 2 octobre 2001 Statut Membre Dernière intervention 8 juillet 2006 - 29 mars 2002 à 08:38
bonjour,
je dois crypter une trame avec un ou exclusif. La trame est une CString. Voici ma fonction:
CString Ccrypto::crypter(CString trameAcrypter)
{
CString cle = "gafokehamegafr";
int i = 0;
int j = 0;
CString trameCrypte;
int nbcarcle = strlen(cle);
int nbcartrame = strlen(trameAcrypter);

for(i = 0; i < nbcartrame; i++)
{
trameCrypte[i] = trameAcrypter[i] ^ cle[j];

if(j == nbcarcle)
{
j = 0;
}
j++;
}

return trameCrypte;

}

--> Le probleme est qu'il y'à une erreur sur la ligne trameCrypte[i] = trameAcrypter[i] ^ cle[j];
L'erreur est : rror C2106: '=' : left operand must be l-value.

Je ne comprend pas, peut on m'aider?
merci

1 réponse

cs_Kaid Messages postés 949 Date d'inscription mardi 2 octobre 2001 Statut Membre Dernière intervention 8 juillet 2006 1
29 mars 2002 à 08:38
Le problème est le 'trameCrypte[i]=...', tu ne peux pas utiliser l'opérateur [] de CString pour faire ca.
Tu dois donc passer par un tableau:

char *trameCrypte=new char [strlen(trameAcrypter) + 1 ];

Ensuite le code reste identique jusqu'au retour:

CString retStr(trameAcrypter);

delete [] trameCrypte.

return retStr;
0
Rejoignez-nous