summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan Lasseter <nathan.je.lasseter@googlemail.com>2012-06-05 19:41:29 +0100
committerNathan Lasseter <nathan.je.lasseter@googlemail.com>2012-06-05 19:41:29 +0100
commit3f9415f3c0ba8186cdf86a616f383a880e9d006e (patch)
tree52e255485978052544c6cae72fb4ea29b9dd147f
SimpleCrypt 0.1 (copied in for historical reasons)
-rw-r--r--Makefile10
-rw-r--r--decrypt.c36
-rw-r--r--encrypt.c36
3 files changed, 82 insertions, 0 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..eaa7d67
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,10 @@
+CFLAGS=-Wall -Wextra
+
+all:
+ make encrypt
+ make decrypt
+
+encrypt: encrypt.c
+ gcc -o $@ $^ ${CFLAGS}
+decrypt: decrypt.c
+ gcc -o $@ $^ ${CFLAGS}
diff --git a/decrypt.c b/decrypt.c
new file mode 100644
index 0000000..3f84bca
--- /dev/null
+++ b/decrypt.c
@@ -0,0 +1,36 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+int main(int argc, char** argv) {
+ if(argc==0) {
+ fprintf(stderr, "Arguments fool!");
+ return 1;
+ }
+ FILE* file = fopen(argv[1], "r");
+ fseek(file, 0, SEEK_END);
+ int length = ftell(file);
+ fseek(file, 0, SEEK_SET);
+ char filearr[length];
+ fread(filearr, length, 1, file);
+ fclose(file);
+ printf("Enter Passphrase:\n");
+ char passphrase[81];
+ fgets(passphrase, 81, stdin);
+ int passlen = strlen(passphrase) - 1;
+ int i=0,j=0;
+ for(i=0;i<length;i++) {
+ if(j==passlen) {
+ j=0;
+ i--;
+ } else {
+ filearr[i] -= passphrase[j];
+ j++;
+ }
+ }
+ file = fopen(argv[1], "w");
+ fwrite(filearr, 1, length, file);
+ fflush(file);
+ fclose(file);
+ return 0;
+}
diff --git a/encrypt.c b/encrypt.c
new file mode 100644
index 0000000..f37b5c0
--- /dev/null
+++ b/encrypt.c
@@ -0,0 +1,36 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+int main(int argc, char** argv) {
+ if(argc==0) {
+ fprintf(stderr, "Arguments fool!");
+ return 1;
+ }
+ FILE* file = fopen(argv[1], "r");
+ fseek(file, 0, SEEK_END);
+ int length = ftell(file);
+ fseek(file, 0, SEEK_SET);
+ char filearr[length];
+ fread(filearr, length, 1, file);
+ fclose(file);
+ printf("Enter Passphrase:\n");
+ char passphrase[81];
+ fgets(passphrase, 81, stdin);
+ int passlen = strlen(passphrase) - 1;
+ int i=0,j=0;
+ for(i=0;i<length;i++) {
+ if(j==passlen) {
+ j=0;
+ i--;
+ } else {
+ filearr[i] += passphrase[j];
+ j++;
+ }
+ }
+ file = fopen(argv[1], "w");
+ fwrite(filearr, 1, length, file);
+ fflush(file);
+ fclose(file);
+ return 0;
+}