From 8330cef7c4e11024d66a3db37bb9b0f22429fbec Mon Sep 17 00:00:00 2001 From: Nathan Lasseter Date: Tue, 5 Jun 2012 19:42:32 +0100 Subject: SimpleCrypt 0.3 (copied in for historical reasons) --- Makefile | 11 +---------- decrypt.c | 43 ------------------------------------------- encrypt.c | 33 ++++++++++++++++++++++++++------- 3 files changed, 27 insertions(+), 60 deletions(-) delete mode 100644 decrypt.c diff --git a/Makefile b/Makefile index df7fbd6..72594d9 100644 --- a/Makefile +++ b/Makefile @@ -1,22 +1,13 @@ CFLAGS=-Wall -Wextra -O3 -all: - make encrypt - make decrypt - encrypt: encrypt.c - gcc ${CFLAGS} -o $@ $^ -decrypt: decrypt.c - gcc ${CFLAGS} -o $@ $^ + gcc ${CFLAGS} ${EFLAGS} -o $@ $^ install: cp encrypt /usr/local/bin/encrypt - cp decrypt /usr/local/bin/decrypt uninstall: rm /usr/local/bin/sc-encrypt - rm /usr/local/bin/sc-decrypt clean: rm encrypt - rm decrypt diff --git a/decrypt.c b/decrypt.c deleted file mode 100644 index b068bb9..0000000 --- a/decrypt.c +++ /dev/null @@ -1,43 +0,0 @@ -#include -#include -#include -#include - -int main(int argc, char** argv) { - /* We need a file to encrypt */ - if(argc==1) { - fprintf(stderr, "Arguments fool!"); - return 1; - } - /* Now lets open that file */ - FILE* file = fopen(argv[1], "r"); - /* And a temporary file to hold the encrypted data */ - char tpath[255] = "/tmp/"; - strcat(tpath, argv[1]); - FILE* temp = fopen(tpath, "w"); - /* Now we need the passphrase. Get it */ - printf("Enter Passphrase:\n"); - char passphrase[255]; - fgets(passphrase, 255, stdin); - int passlen = strlen(passphrase) - 1; - int c,j=0; - /* Now we encrypt! */ - while((c=fgetc(file)) != EOF) { - if(j==passlen) { - fputc(c-passphrase[0], temp); - j=1; - } else { - fputc(c-passphrase[j], temp); - j++; - } - } - /* Close the files */ - fflush(temp); - fclose(temp); - fclose(file); - /* Move the file back */ - char cmd[255]; - sprintf(cmd, "%s %s %s", "/bin/mv", tpath, argv[1]); - system(cmd); - return 0; -} diff --git a/encrypt.c b/encrypt.c index 77249fd..a8cfec1 100644 --- a/encrypt.c +++ b/encrypt.c @@ -3,7 +3,18 @@ #include #include +void sanitise(char *x) { + char *curpos = x; + while (*x != '\0') { + *curpos = *x; + x++; + if (*curpos != '/') curpos++; + } + *curpos = '\0'; +} + int main(int argc, char** argv) { + char * junk; /* We need a file to encrypt */ if(argc==1) { fprintf(stderr, "Arguments fool!"); @@ -13,21 +24,26 @@ int main(int argc, char** argv) { FILE* file = fopen(argv[1], "r"); /* And a temporary file to hold the encrypted data */ char tpath[255] = "/tmp/"; + sanitise(argv[1]); strcat(tpath, argv[1]); FILE* temp = fopen(tpath, "w"); - /* Now we need the passphrase. Get it */ - printf("Enter Passphrase:\n"); + char passphrase[255]; - fgets(passphrase, 255, stdin); + do { + /* Now we need the passphrase. Get it */ + printf("Enter Passphrase:\n"); + junk = fgets(passphrase, 255, stdin); + } while (strlen(passphrase) <= 0); + int passlen = strlen(passphrase) - 1; int c,j=0; /* Now we encrypt! */ while((c=fgetc(file)) != EOF) { if(j==passlen) { - fputc(c+passphrase[0], temp); + fputc(c ^ passphrase[0], temp); j=1; } else { - fputc(c+passphrase[j], temp); + fputc(c ^ passphrase[j], temp); j++; } } @@ -38,7 +54,10 @@ int main(int argc, char** argv) { /* Move the file back */ char cmd[255]; sprintf(cmd, "%s %s %s", "/bin/mv", tpath, argv[1]); - system(cmd); - return 0; + if (system(cmd) != 0) { + fprintf(stderr, "Your encrypted file is located in %s.", tpath); + return EXIT_FAILURE; + } + return EXIT_SUCCESS; } -- cgit v1.2.1