#!/bin/sh

#-------------------------------------------------------------------
# John, testing suite, v1.08.   Jim Fougeron.  
#
# No copyright is claimed, and the software is hereby 
# placed in the public domain. In case this attempt to disclaim 
# copyright and place the software in the public domain is deemed 
# null and void, then the software is Copyright  2011 Jim Fougeron
# and it is hereby released to the general public under the following
# terms: 
#
# This software may be modified, redistributed, and used for any
# purpose, in source and binary forms, with or without modification.
#--------------------------------------------------------------------

if [ x"$JOHN_PATH" = x ]; then
  JOHN_PATH="../run"
  JOHN_EXE="$JOHN_PATH/john"
  UNIQUE="$JOHN_PATH/unique"
  export JOHN_PATH
  export JOHN_EXE
fi

#uncomment the next line, to 'see' the proper command used to call ./tstone with.  Shows how to use tstone by itself to quickly test a problem format, without having to wait for all other testing items to be handled 'first'
#echo ./tstone $1 $2 $3 $4 $5 $6 $7 $8

rm -f tst.rec
rm -f tst.pot
rm -f tst.log

echo $3 | awk '{printf("%-32.32s", $1);}'

if [ ! -s $1.dic ]; then
  echo "File [$1.dic] is missing or empty."
  exit 1
fi

if [ ! -s $2 ]; then
  echo "File [$2] is missing or empty."
  exit 1
fi

EXPARM=
if [ "$5" != "$EXPARM" ]; then
   EXPARM="$4=$5 $6 $7 $8"
fi

#echo dict=$1.dic file=$2
#echo $JOHN_EXE -nolog -config=$JOHN_PATH/john.conf -pot=./tst.pot -sess=./tst -w=./$1.dic $EXPARM $2
JOHN_OUT=`$JOHN_EXE -nolog -config=$JOHN_PATH/john.conf -pot=./tst.pot -sess=./tst -w=./$1.dic $EXPARM $2 2>&1 >/dev/null | awk '{printf("%s %s %s %s %s\n",$1,$2,$3,$4,$5);}' | grep guesses`
# $JOHN_EXE -nolog -config=$JOHN_PATH/john.conf -pot=./tst.pot -sess=./tst -w=./$1.dic $EXPARM $2

if [ "$JOHN_OUT" != "" ]; then
	echo $JOHN_OUT
	echo $3 | cut -b 7-30 | awk '{printf(".pot CHK:  %-21.21s", $1);}'
	CTR=`echo e | tr e '\037'`
	case "$EXPARM" in
          *-fie='\x1F'*)  cut -f 2-8 -d "$CTR" < tst.pot > pw2 ;;
          *)              cut -f 2-8 -d ":"    < tst.pot > pw2 ;;
	esac
	rm -f pw3
	$UNIQUE -inp=pw2 pw3 > /dev/null
	rm -f pw2
	mv tst.pot tst2.pot
	JOHN_OUT=`$JOHN_EXE -nolog -config=$JOHN_PATH/john.conf -pot=./tst.pot -sess=./tst -w=./pw3 $EXPARM $2 2>&1 >/dev/null | awk '{printf("%s %s %s %s %s\n",$1,$2,$3,$4,$5);}' | grep guesses`
	rm -f pw3
	rm -f tst2.pot
	echo $JOHN_OUT
	echo
else
	echo "This hash not able to run on this build of john. Input file is [$2]"
	#exit 2
fi
JOHN_OUT=
EXPARM=

rm -f tst.rec
#rm -f tst.pot
rm -f tst.log
