Cryptographie algorithme XOR
Bonjour,
voila je cherche a mettre en place un algorithme de cryptographie XOR :
Code:
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
| #include <stdio.h>
#include <string.h>
char* xor_crypt(char* key, char* texte)
{
int i;
int c;
char* crypt;
char* cp;
for(i=0; i <= strlen(texte) ; i++)
{
c = texte[i];
if(*cp == NULL)
{
cp = key;
}
c ^= *(cp++);
crypt[i] = c;
}
return crypt;
}
int main()
{
char* crypt_xor;
char* key;
char* texte;
key="okok";
texte="cool la crypto";
crypt_xor = xor_crypt(key, texte);
printf("%s",crypt_xor);
return 0;
} |
Je ne vois vraiment pas ce qui ne va pas mais malherureusement lorsque je compile tout va bien et quand je lance il y a une erreur de segmentation.
Merci d'avance pour votre aide