#!/bin/sh

# Exit on the first command fail
set -e

# Defines expected results
EXPECTED=$(cat <<'EOF'
user_descrypt:Debian
EOF
)

# Defines hashes to crack
HASHES=$(cat <<'EOF'
user_descrypt:AAPKdMk19oAEA
EOF
)

# Temporary hash file to use
TMP="tmp_hashes"
echo "$HASHES" > ${TMP}

# Performs hash cracking by reading the wordlist from stdin
echo "debian Debian" | xargs -n1 | john --stdin --format=descrypt ${TMP}

# Retrieves results
ACTUAL=$(john --show $TMP)

echo "${EXPECTED}" |
    while read line
    do
	echo "${ACTUAL}" | grep -q ${line} 
    done

# Clean up, even if not needed in testbed
rm ${TMP}

# Exit success
exit 0
