Based on this code found on github and the advice given to me on stackoverflow I made this code for the xor in c.
#include <stdio.h>
#include <string.h>
void encryptDecrypt(char *input, char *output)
{
char key[3] = {'K', 'E', 'Y'};
for (int i = 0; i < strlen(input); ++i)
output[i] = input [i] ^ key [i % sizeof(key)];
}
int main()
{
char baseStr[] = "Test";
char encrypted[strlen(baseStr) + 1];
memset(encrypted, '\0', sizeof(encrypted));
encryptDecrypt(baseStr, encrypted);
printf("Encrypted: %s\n", encrypted);
char decrypted[strlen(baseStr) + 1];
memset(decrypted, '\0', sizeof(decrypted));
encryptDecrypt(encrypted, decrypted);
printf("Decrypted: %s\n", decrypted);
return 0;
}
How can I improve the code?