It encrypts the string and then [attempts to] decrypt it, but it fails.
Code:
#include <stdlib.h>
#include <stdio.h>
int enCrypt(char *string, char *key)
{
int y = 0;
int x;
for (x = 0; string[x]; x++)
{
if(!key[x-y])
y += x;
string[x] = string[x]^key[x-y];
string[x]++;
}
return 0;
}
int deCrypt(char *string, char *key)
{
int y = 0;
int x;
for (x = 0; string[x]; x++)
{
if(!key[x-y])
y += x;
string[x] = string[x]^key[x-y];
string[x]++;
}
return 0;
}
int main(int argc, char *argv[])
{
char string[] = "goodbye";
char key[] = "hello";
enCrypt(string,key);
printf("Encrypted:%s\n",string);
deCrypt(string,key);
printf("Decrytped:%s\n",string);
system("PAUSE");
return 0;
}
What is wrong?