Created
October 31, 2015 17:41
-
-
Save toboqus/59a85893ee8c5f13f013 to your computer and use it in GitHub Desktop.
Simple demonstration on using xor to encrypt data with a key, and a demonstration of an attack with both the plaintext and cyphertext
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* xorEncryption.c | |
* | |
* Created on: 30 Oct 2015 | |
* Author: Alex | |
*/ | |
#include <stdio.h> | |
#include <string.h> | |
int main(void) | |
{ | |
char password[14] = "ABCDEFGHIJKLMN"; | |
char plaintext[14] = "this is secure"; | |
char cyphertext[14]; | |
char computedKey[14]; | |
for(int i = 0; i < 14; i++){ | |
cyphertext[i] = plaintext[i] ^ password[i]; | |
} | |
printf("Encrypted data: %s\n", cyphertext); | |
for(int i = 0; i < 14; i++){ | |
computedKey[i] = cyphertext[i] ^ plaintext[i]; | |
} | |
printf("Key used to encrypt the data: %s\n", computedKey); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output:
Encrypted data: 5**7e/4h:/(9?+
Key used to encrypt the data: ABCDEFGHIJKLMN