//XOR Encrypt 0.0.2 //by Sean Kane - http://celtickane.com #include #include //needed for exit() #include #define MAX_SIZE 80 //change this if you want larger buffers void crypt(char bufData[], char bufKey[]); int main() { char bufData[MAX_SIZE], bufKey[MAX_SIZE]; char chrPrompt; for (;;) { printf("(E)ncrypt, (D)ecrypt, (Q)uit: "); chrPrompt = getchar(); switch( chrPrompt) { case 'e': case 'E': fflush(stdin); //Get rid of any garbage printf("Enter word to encrypt: "); gets(bufData); printf("Enter encryption key: "); gets(bufKey); crypt(bufData, bufKey); printf("Encrypted data: %s\n", bufData); break; case 'd': case 'D': fflush(stdin); //Get rid of any garbage printf("Enter word to decrypt: "); gets(bufData); printf("Enter encryption key: "); gets(bufKey); crypt(bufData, bufKey); printf("Decrypted data: %s\n", bufData); break; case 'q': case 'Q': exit(1); break; default: printf("Please type E, D, or Q\n"); break; } //end switch } //end for return 0; } //end main void crypt(char bufData[], char bufKey[]) { int iData, iKey; iKey = 0; for(iData = 0; iData < strlen(bufData); iData++) { bufData[iData] = bufData[iData] ^ bufKey[iKey]; (iKey == (strlen(bufKey) -1)) ? iKey = 0 : iKey++; } }