summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSeppia <nonso@insicuri.net>2016-06-13 22:16:32 +0200
committerSeppia <nonso@insicuri.net>2016-06-13 22:16:32 +0200
commit0692bf8e24bbb2493f23f81ffb4d84615180f939 (patch)
tree7124c91512cafeeaea62fa8c86b0c89b7e929336
parentbdfe51843317bc42cadcd6d5326b8d90aa26e58d (diff)
downloadonetimebluh-0692bf8e24bbb2493f23f81ffb4d84615180f939.tar.gz
onetimebluh-0692bf8e24bbb2493f23f81ffb4d84615180f939.tar.bz2
onetimebluh-0692bf8e24bbb2493f23f81ffb4d84615180f939.zip
added key rosicchiamento code (test)
-rw-r--r--rosicchio.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/rosicchio.c b/rosicchio.c
new file mode 100644
index 0000000..53f714e
--- /dev/null
+++ b/rosicchio.c
@@ -0,0 +1,43 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+int main(int argc, char* argv[]) {
+
+ FILE* mess = fopen(argv[1], "r");
+ FILE* pad = fopen(argv[2], "r+");
+ FILE* critt = fopen(argv[3],"w");
+ fseek(mess, 0L, SEEK_END);
+ long mess_size = ftell(mess);
+ rewind(mess);
+ fseek(pad, 0L, SEEK_END);
+ long pad_size = ftell(pad);
+ fseek(pad, (pad_size - mess_size), SEEK_SET);
+ int i = 1;
+ char a, b;
+
+ while(i != EOF) {
+ i = fscanf(mess, "%c", &a);
+ fscanf(pad, "%c", &b);
+ if(i != EOF) {
+ fprintf(critt, "%c", a^b);
+ }
+ }
+
+ /* The truncate function "rosicchia" la parte di chiave utilizzata */
+
+ truncate(argv[2], (pad_size - mess_size));
+ fseek(pad, 0L, SEEK_END);
+ long new_pad_size = ftell(pad);
+
+ fclose(mess);
+ fclose(pad);
+ fclose(critt);
+
+ printf("Message length is %li bytes \n", mess_size);
+ printf("Pad length was %li bytes \n", pad_size);
+ printf("Pad length is now %li bytes \n", new_pad_size);
+ printf("Pad length should now be %li bytes \n", (pad_size - mess_size));
+
+ exit(EXIT_SUCCESS);
+}