Last active
August 13, 2016 10:44
-
-
Save shkesar/1745ca53f238e08f03df1b2766044b2f to your computer and use it in GitHub Desktop.
XOR based cipher program in C
This file contains hidden or 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
#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; | |
} |
This file contains hidden or 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
#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