summaryrefslogtreecommitdiff
path: root/task4.c
diff options
context:
space:
mode:
authorBenedict <benedict@0xb8000.de>2016-03-19 13:44:55 +0100
committerBenedict <benedict@0xb8000.de>2017-02-21 13:00:24 +0100
commit4a9770b8ba9d86db12779f5ae00366bce60a42ad (patch)
tree760dee07368fa25141e2467d21128486f5e5e7f8 /task4.c
parent236d0ee8acedc2535a4a973acd99a708b530a053 (diff)
completed task6 nearly completly
just a few characters are still wrong in the key. freqencies analysis has to be made more comprehensive
Diffstat (limited to 'task4.c')
-rw-r--r--task4.c26
1 files changed, 11 insertions, 15 deletions
diff --git a/task4.c b/task4.c
index a1b7b28..11fab98 100644
--- a/task4.c
+++ b/task4.c
@@ -1,19 +1,17 @@
#include "lib.h"
-void main() {
+int main() {
/** read the file */
FILE *fp;
- int bytes_read;
int malloc_size = 62;
int line_number = 0;
int j;
+ char key;
char *string = malloc(malloc_size);
char *string2 = malloc(malloc_size);
char *cleartext = malloc(malloc_size);
- char *keys = malloc(255);
- char single_key;
- int length;
+ struct key_and_freq tmp;
fp = fopen("4.txt", "r");
@@ -23,19 +21,17 @@ void main() {
}
while (fscanf(fp, "%61c", string) != EOF) {
+ tmp.hits = 0;
j = decode_hex_string(string, string2);
- length = brute_force_single_byte_xor(string2, j, keys);
- if (length > 0) {
- printf("line %i:\n", line_number);
- for(j=0;j<length;j++) {
- single_key = keys[j];
- xor_string(string2, &single_key, cleartext, 1, 60);
- printf("%s\n", cleartext);
- }
- }
+ key = brute_force_single_byte_xor(string2, j, &tmp);
+ xor_string(string2, &key, cleartext, 1, j);
+ if ((!isprintable(cleartext, j)) || (tmp.hits < 10))
+ continue;
+
+ printf("%s", cleartext);
line_number++;
}
fclose(fp);
-
+ return 0;
}