From 4fcdea6cfd4571d5d2e66a4f23ae572ab5d9f6cb Mon Sep 17 00:00:00 2001
From: Moritz Eckert <mo@mightym0.de>
Date: Wed, 13 Jun 2018 15:38:11 +0200
Subject: [PATCH] Add output parsing

---
 hpc/torque/parse-output.py | 39 ++++++++++++++++++++++++++++++++++++++
 hpc/torque/start.sh        | 27 +++++++++++++++++++++++++-
 src/mpi/mpi-layer.c        |  2 +-
 3 files changed, 66 insertions(+), 2 deletions(-)
 create mode 100755 hpc/torque/parse-output.py

diff --git a/hpc/torque/parse-output.py b/hpc/torque/parse-output.py
new file mode 100755
index 0000000..12a50fb
--- /dev/null
+++ b/hpc/torque/parse-output.py
@@ -0,0 +1,39 @@
+#!/usr/bin/env python2
+
+import sys
+import re
+
+
+if len(sys.argv) < 3:
+    print("USAGE: {} codebreaker.out codebreaker.found".format(sys.argv[0]))
+    sys.exit(1)
+with open(sys.argv[1], "r") as f:
+    raw = f.read()
+
+start, filtered, end = re.findall(r"End of prologue: \w+ \w+ (\d+ \d+:\d+:\d+)([\n\w\W\d\D\s\S]+)Starting epilogue... \w+ \w+ (\d+ \d+:\d+:\d+)", raw, re.MULTILINE)[0]
+
+s_day, s_time = start.split(' ')
+s_day = int(s_day)
+s_hour, s_min, s_sec = map(int, s_time.split(':'))
+
+e_day, e_time = end.split(' ')
+e_day = int(e_day)
+e_hour, e_min, e_sec = map(int, e_time.split(':'))
+
+time_diff = (e_day-s_day)*24*3600 + (e_hour-s_hour)*3600 + (e_min-s_min)*60 + (e_sec-s_sec)
+
+result = ''
+total = 0
+for line in filtered.split('\n')[1:-1]:
+    try:
+        salt, pwd, _hash = re.findall(r"NODE\[\d+\]: \|(.*)\|(.*)\|(.*)\|", line)[0]
+    except IndexError:
+        continue
+    result += "|SALT='{}'|PWD='{}'|HASH={}|\n".format(salt, pwd, _hash)
+    total += 1
+
+header = 'Codebreaker recovered {} passwords in {} seconds:\n'.format(total, time_diff)
+
+with open(sys.argv[2], "w") as f:
+    f.write(header)
+    f.write(result)
diff --git a/hpc/torque/start.sh b/hpc/torque/start.sh
index daac016..755391d 100755
--- a/hpc/torque/start.sh
+++ b/hpc/torque/start.sh
@@ -1,3 +1,28 @@
 #!/bin/bash
 
-qsub -l nodes=2:ppn=40 -M moritz.eckert@fau.de torque.sh
+rm codebreaker.out codebreaker.err
+
+echo "Starting codebreaker..."
+qsub -l nodes=2:ppn=40 -M moritz.eckert@fau.de torque.sh > job.id
+
+echo -n "Running..."
+ready=0
+while [ $ready -eq 0 ];
+do
+    qstat `cat job.id` > /dev/null 2>&1
+    ready=$?
+    echo -n '.'
+    sleep 1
+done
+
+echo ""
+echo "Done!"
+echo -n "Waiting for results..."
+
+while [ ! -f codebreaker.out ]; do
+    echo -n "."
+    sleep 1
+done
+
+./parse-output.py codebreaker.out codebreaker.found
+cat codebreaker.found
diff --git a/src/mpi/mpi-layer.c b/src/mpi/mpi-layer.c
index 2ade640..d59f4e7 100644
--- a/src/mpi/mpi-layer.c
+++ b/src/mpi/mpi-layer.c
@@ -49,7 +49,7 @@ void node_logic (int rank, int size, char *wlist, char *plist) {
 			}
 			if (check_pass (&hashes[h].ctx, get_vector(&words_dist, w), hashes[h].salt, hashes[h].hash)) {
 				hashes[h].done = 1;
-				printf("PID[%d]: (%s)%s == %s.\n", rank, hashes[h].salt, get_vector(&words_dist, w), hashes[h].hash);
+				printf("NODE[%d]: |%s|%s|%s|\n", rank, hashes[h].salt, get_vector(&words_dist, w), hashes[h].hash);
 			}
 		}
 	}
-- 
GitLab