Last active
August 29, 2015 14:17
-
-
Save lion328/14f271c64822f76c6b0c to your computer and use it in GitHub Desktop.
Natty
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 <string.h> | |
#include <stdlib.h> | |
void natty_encrypt(char *in, char *out) { | |
for(int i = 0; in[i]; i++) out[i] = in[i] + i; | |
} | |
void natty_decrypt(char *in, char *out) { | |
for(int i = 0; in[i]; i++) out[i] = in[i] - i; | |
} | |
void doProcess(void (*function)(char *, char *), char *in) { | |
char *buf = (void *)0; | |
buf = malloc(strlen(in)); | |
function(in, buf); | |
printf("%s\n", buf); | |
if(buf != (void *)0) free(buf); | |
} | |
int main(int argc, char **argv) { | |
if(argc < 3) return 0; | |
for(int i = 1; i < argc; i++) { | |
if(strcmp(argv[i], "--encrypt") == 0) { | |
doProcess(&natty_encrypt, argv[++i]); | |
return 0; | |
} | |
else if(strcmp(argv[i], "--decrypt") == 0) { | |
doProcess(&natty_decrypt, argv[++i]); | |
return 0; | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment