Skip to content

Instantly share code, notes, and snippets.

@shkesar
Last active August 13, 2016 10:44
Show Gist options
  • Save shkesar/1745ca53f238e08f03df1b2766044b2f to your computer and use it in GitHub Desktop.
Save shkesar/1745ca53f238e08f03df1b2766044b2f to your computer and use it in GitHub Desktop.
XOR based cipher program in C
#include <stdio.h>
#include <stdlib.h>
#define MAX_LEN 1024
int main(int argc, char const *argv[])
{
char *plain = malloc(MAX_LEN * sizeof(int));
char *pass = malloc(MAX_LEN * sizeof(int));
char *pass_backup = pass;
fgets(plain, MAX_LEN, stdin);
fgets(pass, MAX_LEN, stdin);
while (*plain) {
if (!*pass) pass = pass_backup;
printf("%c", *plain++ ^ *pass++);
}
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#define MAX_LEN 1024
int main(int argc, char const *argv[])
{
FILE *plain_f = fopen(argv[1], "r");
FILE *cipher_f = fopen(argv[2], "w+");
char *plain = malloc(MAX_LEN * sizeof(int));
const char *pass = argv[3];
fgets(plain, MAX_LEN, plain_f);
while (*plain) {
if (!*pass) pass = argv[3];
fprintf(cipher_f, "%c", *plain++ ^ *pass++);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment