I need some help with a XOR program I'm trying to write.
I need to know if I'm on the right track here, and how I could decrypt it all. Reverse the process, so to speak. Please have a look at this code, but ignore all the unnecessary printf's, I'm just trying to follow the code through step by step.
Are the for loops correct? I found some pseudo code in the forum which I decided to write the code from..
If the encryption is in order, which I believe it is, then there's the small matter of decrypting it.. The process has to be reversed, that much I know, but it seems it will only decrypt as many characters as the key is based on. Somwhere, somehow, this needs to increment..
itsme86, you've been of great help explaining the modulo and the caesar program. You mind taking a peek at this?
Code:
#include <stdio.h>
#include <string.h>
main()
{
char plain[51];
char encry[51];
char key[5] = "ABCD";
int i, keylen = 0, keypos = 0;
printf("Enter text: ");
scanf("%[^\n]", plain);
printf("You entered: %s\n", plain);
keylen = strlen(key);
printf("Encyption key is: %s\n", key);
printf("Length of key is: %d\n", keylen);
for ( i = 0; plain[i] != '\0'; i++ )
{
encry[i] = plain[i] ^ key[keypos];
keypos++;
if ( keypos > keylen )
keypos = 0;
}
printf("\nEncrypted text: %s\n", encry);
for ( i = 0; encry[i] != '\0'; i++ ) {
plain[i] = encry[i] ^ key[i]; /*???*/
/* ??? */
}
printf("Decrypted: %s", plain);
fflush(stdin);
getchar();
}