Skip to content

Instantly share code, notes, and snippets.

@toboqus
Created October 31, 2015 17:41
Show Gist options
  • Save toboqus/59a85893ee8c5f13f013 to your computer and use it in GitHub Desktop.
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
/*
* 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);
}
@smamran
Copy link

smamran commented Feb 23, 2016

learning

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment