1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> char* XORCipher(char* data, char* key, int dataLen, int keyLen) { char* output = (char*)malloc(sizeof(char) * dataLen); for (int i = 0; i < dataLen; ++i) { output[i] = data[i] ^ key[i % keyLen]; } return output; } int main(void) { char text[] = "This is a house."; char key[] = "123456"; int dataLen = strlen(text); int keyLen = strlen(key); char* cipherText = XORCipher(text, key, dataLen, keyLen); char* plainText = XORCipher(cipherText, key, dataLen, keyLen); printf("¾ÏÈ£È ÀüÀÇ ¹®ÀÚ¿=%s\n", text); printf("¾ÏÈ£È Å°=%s\n", key); printf("¾ÏÈ£È ÈÄÀÇ ¹®ÀÚ¿=%s\n", cipherText); } | cs |