#!/bin/sh
# 
# Shell Script for joining JOHN THE RIPPER and WEPDECRYPT
# by Dominik Blunk and Alain Girardet and Fernando Tarin
#
# Incremental mode of john
#
# usage: ./run_inc DUMPFILE [MAC_ADDRESS] [NUMBER_NETWORKS]
#

# Edit /etc/wepdecrypt.conf for configuration
. /etc/wepdecrypt.conf

#
# command to join JOHN RIPPER and WEPDECRYPT
#

if which john &> /dev/null; then
	JOHNDIR=`which john | awk -F / '{for (i=1; i<=NF-1; i++){ printf "%s/", $i };}'`
fi

if [ $# -lt 1 -o $# -gt 3 ]; then
	echo "Usage: $0 Dumpfile [mac_address] [number_networks]";
	exit 1;
fi

if ! [ -f $1 ]; then
	echo "Error: Dumpfile '$1' does not exist.";
	exit 1;
fi

if [ $# -eq 1 ]; then 
	if test -f $JOHNDIR/john; then
		$JOHNDIR/john -incremental -stdout:13\
	 	| wepdecrypt -f $1;
		exit 0;
	else
		echo "John the ripper not found! Edit '/etc/wepdecrypt.conf' ";
		echo "to set correct path...";
		exit 1;
	fi
fi

if [ $# -eq 2 ]; then
	if test -f $JOHNDIR/john; then
                $JOHNDIR/john -incremental -stdout:13\
                | wepdecrypt -f $1 -b $2;
		exit 0;
	 else
                echo "John the ripper not found! Edit '/etc/wepdecrypt.conf' ";
                echo "to set correct path...";
                exit 1;
        fi
fi

if [ $# -eq 3 ]; then
        if test -f $JOHNDIR/john; then
                $JOHNDIR/john -incremental -stdout:13\
                | wepdecrypt -f $1 -b $2 -n $3;
                exit 0;
        else
                echo "John the ripper not found! Edit '/etc/wepdecrypt.conf' ";
                echo "to set correct path...";
                exit 1;
        fi
fi
