I would like some guidance
/* Here is some code you can use to very lightly encrypt a string / / This if just off the top of my head, so the non-production quality / / should be pretty obvious :) And this is in C, not C++, as C is my / / personal language of choice. */
#include <stdio.h> #include <stdlib.h> #include <string.h>
int main(int argc, char *argv[]) {
char to_be_encrypted[50]; char encrypted_string[50]; char key = 'H'; int index;
printf("Input a string to be encrypted: " ); gets(to_be_encrypted);
for (index = 0; index < strlen(to_be_encrypted); index++) {
encrypted_string[index] = to_be_encrypted[index] ^ key;
/* ^ character is for binary XOR operation /
}
encrypted_string[index] = '\0';
/ Add terminating null character to string*/
printf("\nYour encrypted string is: %s",encrypted_string);
for (index = 0; index < strlen(encrypted_string); index++) { encrypted_string[index] ^= key; /* You can decrypt with the same key */ }
printf("\nYour decrypted string is: %s\n",encrypted_string);
return 0;
}
In the event that you get a character and a key that XOR out to a binary 0 (01001100 XOR 01001100 for example), the printf( "%s" ) will only print the characters before the NULL terminator. Easy to circumvent, I just thought I should mention it.
Also, this exact style of encryption is used for a certain unnamed App challenge, for those of you who might have needed a hint :)
/* Bah, damn smilies */